Overview:
We recently implemented an automated approval process in SharePoint Online with Power Automate for a construction and engineering company based out of Washington, United States. We came across a scenario where we required to consume SharePoint data in Power Automate with REST API using Client ID & Client Secret. Here in this article, we will discuss step by step process to implement such functionality.
Prerequisite:
We must have SharePoint App registered, please visit this article for step by step process to register the SharePoint App.
Copy Tenant ID from Azure Portal:
Steps to call SharePoint REST APIs with Client ID and Client Secret from Power Automate (MS Flow)
- Initialize variables for – Client ID, Client Secret, Tenant Name and Tenant ID.
- Client ID and Client Secret = We can get these from where we registered the App.
- Tenant Name = Name of the Tenant.
-
Tenant ID = We can get that from Azure Portal (Step 2 from above
section).
-
Prepare Body Variable.
grant_type=client_credentials&client_id=<<Client ID>>@<<TenantID>>&client_secret=<<Client Secret>>&resource=00000003-0000-0ff1-ce00-000000000000/<<TenantName>>.sharepoint.com@<<TenantID>>
- Now, add “HTTP action”.
- Method: POST
- URI: https://accounts.accesscontrol.windows.net/@{variables('tenantID')}/tokens/OAuth/2
- Headers: Content-Type: application/x-www-form-urlencoded
- Body: Pass the variable defined in Step 2.
-
Get Access token in Compose Variable.
Expression: body('Get_Access_Token_from_SharePoint')['access_token'] - Add HTTP Action to get users from SharePoint group.
- Method: Get
- URI: https://tenantname.sharepoint.com/sites/sitename/_api/web/sitegroups/getbyname('groupname')/users
- Headers:
- Accept: application/json;odata=verbose
Authorization: Bearer @{outputs('Compose')} - Then, let’s Parse our JSON using Select Statement.
This is how we can create a flow to find the users from SharePoint Group with
client Id and client secret.
Test Flow
The flow ran successfully.
We got the following access token using first API call.
Then this access token used to call the group users. We got the following
users.
Conclusion:
This is how, we can call SharePoint Rest API with Client ID and Client Secret
from Power Automate. Isn’t that amazing?
If you have any questions you can reach out our
SharePoint Consulting
team
here.
No comments:
Post a Comment