How To Create A Sharing Link For Files In Power Automate
How To Create A Sharing Link For Files In Power Automate Posted by - Matthew Devaney on - January 14, 2024 33 Comments Sharing links can be used to give acce...
- Published
- Reading time
- 7 min read
Before you start
Is this guide for you?
- Best entry point
- Power Automate
- Time investment
- 7 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/how-to-create-a-sharing-link-for-files-in-power-automate/. Author: Matthew Devaney.
How To Create A Sharing Link For Files In Power Automate Posted by - Matthew Devaney on - January 14, 2024 33 Comments
Sharing links can be used to give access to a file without granting access to the entire document library or site. With Power Automate, you can create a sharing link for anonymous users , people in your organization or specific internal or external users . You can define whether users have edit or view permissions and even set an expiration date. In this article I will show you how to create a sharing link for files in Power Automate. Table of Contents
Introduction: The Vendor Invoice Sharing Link Flow Setup The SharePoint Document Library Create A Sharing Link In Power Automate Send The Sharing Link In An Email
Get The Drive ID For The Sharing Link File
Obtain The File ID For The Sharing Link File Create Sharing Link For Specific Users
Send The Sharing Link To Specific Users Via Email
Run The Flow To Send A Sharing Link For Specific Users
Introduction: The Vendor Invoice Sharing Link Flow
Employees in the Accounts Payable department of a company share use an automation to share invoices with colleagues in other departments. The flow creates a share link so that users can access the file without being granted permission to the entire document library. Sharing Link
For Anonymous Users Or People In Your Organization Setup The SharePoint Document Library
Open SharePoint and create a new document library called Vendor Invoices . Add several files to the document library to share with other users.
Choose a file to share using Power Automate. In this example we will share the following file: Name – Adatum 4.pdf ID – 13 Document Library – Vendor Invoices Create A Sharing Link In Power Automate
In Power Automate start a new flow with an instant trigger. Add a SharePoint – Create Sharing Link For A File Or Folder action. Choose the Vendor Invoices library and supply the Item Id for the file we want to share. The Link Type controls whether the user can edit or view the file.
Select who can access the file using the Link Scope . Anyone with the link, including anonymous will allow users outside of the organization to access the file.
People in your organization limits access to only users in the same tenant.
After the link is created we want to send it to a user. Insert the Outlook – Send An Email (V2) action and choose a recipient.
Use this code in the Body of the Send An Email action to include a clickable link to the file. < p >
A file has been shared from Power Automate: < a
href = "@{outputs('Create_sharing_link_for_a_file_or_folder')?['body/link/webUrl']}" > Adatum 4.pdf </ a > </ p > Code language: HTML, XML ( xml ) Send The Sharing Link In An Email
Now that the basic flow is created we will test sending the user a sharing link via email. Save the flow and test it manually.
The recipient will receive an email. Ask them to click the link to the file.
For an Anonymous link type anyone can see the file without the need to login. Or for a People in your organization link type the user will need to login with a company email. Sharing Link For Specific Users
Get The Drive ID For The Sharing Link File
To create a sharing link for a specific internal user we must utilize the SharePoint Rest API. This will require us to know the Drive ID for the SharePoint document library and the Item ID for the file.
First we will find the Drive ID . Add a SharePoint – Send An HTTP Request action to the flow and select the GET Method.
Use this URI to return a list of all document libraries for the selected site. _api/v2.0/drives
Include the following headers in the request. Key Value Accept application/json
Filter the values returned by the SharePoint HTTP action where the drive name equals Vendor Invoices . item () [ 'name' ] Code language: CSS ( css )
Store the result of the Data Operations – Filter Array action in a variable named varDriveId . Use the following expression to get the ID of the first value in the array.
first(body( 'Filter_array:_name_eq_Vendor_Invoices' ))?[ 'id' ] Code language: JavaScript ( javascript )
Obtain The File ID For The Sharing Link File
The Item ID for Adatum 4.pdf can be found using a similar method to the Drive ID . Add another SharePoint – Send An HTTP Request action to the flow and use the GET method.
Use this code in the Uri to get all of the files in the Vendor Invoices document library’s root directory.
_api/v2 .0 /drives/@{variables( 'varDriveId' )}/items/root/children Code language: JavaScript ( javascript ) Include these headers in the request. Key Value Accept application/json
Then, in the Filter action use this code in the From field to operate on the file values returned by the SharePoint HTTP action .
body( 'Send_an_HTTP_request:_Get_Items' )[ 'value' ] Code language: JavaScript ( javascript )
Use this code in the left side of the filter comparison to check the name field. item () [ 'name' ] Code language: CSS ( css )
Then save the Item ID in a variable named varItemId using this expression.
first(body( 'Filter_array:_name_eq_Filename' ))?[ 'id' ] Code language: JavaScript ( javascript ) Create Sharing Link For Specific Users
Now that we have the Drive ID and the Item ID we can create the sharing link for specific users. Load an array of user emails into a Data Operations – Compose action. Then create the sharing link with a SharePoint – Send An HTTP Request action using the POST method.
Construct this array inside of the Compose action and replace the email addresses your own email addresses. Notice that both external and internal email addresses are included. [ { "email" : " [email protected] " }, { "email" : " [email protected] " }, { "email" : " [email protected] " } ] Code language: JSON / JSON with Comments ( json )
Use this code in the Uri property of the SharePoint HTTP action to create a sharing link.
_api/v2 .0 /drives/@{variables( 'varDriveId' )}/items/@{variables( 'varItemId' )}/createLink Code language: JavaScript ( javascript )
Include these values in the HTTP Request headers. Key Value Accept application/json
Supply this JSON payload in the body of the HTTP request. Type can be either view or edit .
Scope is set to users meaning specific users must be defined. Tell the HTTP request who can use the sharing link in the recipients property. { "type" : "edit" , "scope" : "users" ,
"recipients" : @{outputs( 'Compose:_Specific_Users' )} } Code language: JavaScript ( javascript )
Send The Sharing Link To Specific Users Via Email
The sharing link has been created for specific users. Now it must be sent to those users in an email. Start by adding a Data Operations – Select action and loading the From field with the Outputs of the Compose: Specific Users action used earlier in the flow.
Switch the Select action to Text Mode and use this code in the Map property. item ()? [ 'email' ] Code language: CSS ( css )
Here is a screenshot showing what the Select action does.
Then insert an Outlook – Send An Email (V2) action with the subject Sharing Link To File Adatum 4.
Use this code in the To field to join the email addresses with a semi-colon as the delimeter.
join(body( 'Select:_User_Emails' ), ';' ) Code language: JavaScript ( javascript )
Write this HTML in the body of the message to display the sharing link. < p >
A file has been shared from Power Automate: < a
href = "@{body('Send_an_HTTP_request:_Sharing_Link_Specific_Users')?['link']?['webUrl']}" > Adatum 4.pdf </ a > </ p > Code language: HTML, XML ( xml )
Run The Flow To Send A Sharing Link For Specific Users
We’re done. Save and run the flow to send the sharing link.
The sharing link email appears in the inbox of the users it was sent to.
The specific user is able to open the file as expected. Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions or feedback about How To Create A Sharing Link For Files In Power Automate please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney Power Automate
Save Docusign Document To SharePoint With Power Automate
Tagged
Power Automate
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action