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 an anonymous access sharing link of document using the REST API from Power Automate.

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

Use the “Send an HTTP request to SharePoint” action to call the REST API. There are two ways to create a sharing link using REST API. The difference between them is in the URI: 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 the URI to create a sharing link. Refer to the screenshot and details below.

REST API to share link of document from Power Automate.

 

Let's 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 the second approach we will use File URL in URI to create a sharing link. Refer to the screenshot and details below.

Let's review all the parameter values shown in the 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
    }
  }
}

Recent Posts