Invoke SharePoint REST API using Power Automate Desktop

This blog is a continuation of a previous blog post , in which we used the SharePoint client object model (CSOM) to get SharePoint List items. In this blog, we will learn how we can “Invoke SharePoint Online REST APIs” using Power Automate Desktop.

The blog is majorly divided into two parts:

  • Granting access using SharePoint App-Only Authentication.
  • Building the Power Automate Desktop Flow to “Invoke SharePoint REST APIs”.

So without wasting any further time let’s Configure SharePoint Online to use App-Only Authentication:

Part 1: Granting access using SharePoint App-Only Authentication.

Step 1:

Step 2: 

Once the Client Id & Client Secret are generated successfully, you will be redirected to a new page as shown in the screenshot below with your app details. Note down the Client Id and Client Secret values. We will be using them in the next steps.

Step 3:

The ext step is granting permissions to the newly created principal.  You can reach this site via https://<YourSharePointSiteCollection>/_layouts/15/appinv.aspx. Once the page is loaded add your client id and look up the created principal:

  • Copy the Client Id from Step 2 and paste it in the App Id field and click on the Lookup button. It will automatically fetch the  App details.
  • Copy & Paste below XML in Permission Request XML section.
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>

When you click on Create you’ll be presented with a permission consent dialog. Press Trust It to grant the permissions:

Step 4:

We will need the Tenant-Id to “Invoke the SharePoint REST API” . To get the Tenant-Id Navigate to https://<YourSharePointCollectionURL>/_layouts/15/appprincipals.aspx

Note: The GUID after the @ symbol is the Tenant-Id.

You have successfully Configured you SharePoint to us App Only Authentication.

Part 2: Building the Power Automate Desktop Flow to “Invoke SharePoint REST APIs”

From a high level, our Power Automate Desktop solution would look like the screenshot below –

Step 1:

Launch the application and select New flow in the console. Enter a name for the desktop flow, and select Create.”

Step 2:

Add the “Invoke a web service” request action to the Power Automate Desktop Canvas and set the Parameters with reference to the details below:

grant_type=client_credentials
&client_id=client_id@tenant_id
&client_secret=client_secret
&resource=00000003-0000-0ff1-ce00-000000000000/YourSharepointOnlineDomainName@tenant_id

Step 3:

Add the “Convert JSON to custom object” action to the Power Automate Canvas and set the parameter below:

  • JSON: %WebServiceResponse% the Output of the “Invoke Web service” action

Step 4:

Add the “Invoke a web service” request action to the Power Automate Desktop Canvas and set the Parameters with reference to the details below:

In this example, we will get the list items from a SharePoint List.

In the Power Automate “Invoke a web service” action under the “Advanced” setting set the “Follow redirection” and “Encode request body” to OFF.

Step 5:

Add the “Convert JSON to custom object” action to the Power Automate Canvas and set the parameter below:

  • JSON: %WebServiceResponse2% the Output of the “Invoke Web service 2” action,

Step 6:

Add the “For each” action to the Power Automate Desktop Canvas and set the parameter below:

Step 7:

Inside the “For each” loop add the “Display message” action and set the Parameter below. Note: Here you can add any other action and further work with the list items e.g. write the items to a file , etc.

That is it, run the Power Automate Desktop Flow and who should see the Tittle column displayed in a Pop-up box.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s