REST API to share link of document from Power Automate.

2 min read

If you want to communicate with SharePoint from Power Automate the Rest API is one of the best options to use as it provides you lot of flexibility.

In this blog post you will learn how to create anonymous access sharing link of document using Rest API from Power Automate.

Please note that there is already an action “Create sharing link for a file or folder” available in Power Automate to do this, but you can use REST API in special cases e.g. when you use Library GUIDE instead of Library Title to generate the sharing link, or when you want to use dynamic values for Library/File name.

Use “Send an HTTP request to SharePoint” action to call the REST API. There are two ways to create sharing link using REST API, in both ways the difference is only in the Uri part, the body payload json is same in both approaches.

First Approach

In first approach we will use List GUID/List Title and Item ID in Uri to create sharing link, refer below screenshot and details.

REST API to share link of document from Power Automate.

Lets review all the parameter values shown in above screenshot:

    1. Site Address: Provide the Site URL where your Library resides.
    2. Method: POST (as we want to make create the sharing link in SharePoint)
    3. Uri: _api/web/lists(guid’A4E78CC7-F74F-4733-832A-099D945908A8′)/items(39)/sharelink
      1. Replace A4E78CC7-F74F-4733-832A-099D945908A8 with your Library GUID.
      2. Replace 39 with your item ID
      3. Alternatively, if you don’t have Library GUID you can use Library Title, sample Uri below.

_api/web/lists/GetByTitle(‘Documents’)/items(39)/sharelink
Here replace Documents with your library title and replace 39 with your item id.

Second Approach

In second approach we will use File URL in Uri to create sharing link, refer below screenshot and details.

Lets review all the parameter values shown in above screenshot:

      1. Site Address: Provide the Site URL where your Library resides.
      2. Method: POST (as we want to make create the sharing link in SharePoint)
      3. Uri: _api/web/GetFileByUrl(@v)/ListItemAllFields/ShareLink?@v=’/sites/development/Shared%20Documents/book1.xlsx’
        1. Replace ‘/sites/development/Shared%20Documents/book1.xlsx’ with your site relative file URL.

Below is the payload to use in both approaches in body parameter of action:

{
  "request":
  {
    "createLink":true,
    "settings":
    {
      "allowAnonymousAccess":true,
      "linkKind":2,
      "expiration":null,
      "restrictShareMembership":false,
      "updatePassword":false,
      "password":"", 
      "description":"My description", 
      "role":8,
      "applicationLink":false,
      "limitUseToApplication":false
    }
  }
}