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.
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.
Let's review all the parameter values shown in above screenshot:
api/web/lists/GetByTitle(‘Documents’)/items(39)/sharelink
Here, replace Documents with your library title and replace 39 with your item ID.
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:
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 } } }