In this post, I will be showing you the steps with instructions to call Microsoft graph Endpoints as a daemon app using Application permissions with the help of HTTP connector. Calling graph from a flow opens a wide range of possibilities which are not available with the prebuilt connectors. As of now you will not be able to call Microsoft graph with application permissions using a custom connector.
Pre-Requisites:
- Access to HTTP Premium Connector in Power Automate
- Access to register Azure AD Application in Azure AD Portal Application Registration in Azure AD Portal: Register an application in Azure AD and obtain the client id, client secret & tenant id for the registered application. In this example I have added the Application permission Calendars.Read to access all the recent events of a user from Outlook.
It is not required in the Azure AD application to have a redirect URI.
Power Automate Flow:
It is now time to generate the graph token using the HTTP connector in flow which is a pre-requisite to call the Graph API endpoint. The only authentication flow to generate a access token for application permissions is Client credentials.
To generate a token
Store the Client Secret on a String variable
Make a HTTP request using the HTTP connector with the following details. Make sure to replace the string for tenantId, azureAdAppclientId and azureAdAppclientSecret
Method 1:
Add a HTTP connector action to the flow for making a POST request per the following information
HTTP Method: POST
URI: https://login.microsoftonline.com/yourtenantId/oauth2/v2.0/token
Headers: Content-Type: application/x-www-form-urlencoded
Body:
Replace the tenantId, client id and client secret from the variable
tenant=yourtenantId&client_id=azureAdAppclientId&client_secret=@{decodeUriComponent(variables('azureAdAppclientSecret'))}&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
For the client secret make sure to URL encode using the expression encodeUriComponent(variables(‘clientSecret’)) else the request will fail due to the presence of special characters.
To extract the token from the above request, add the parse JSON action with Content from the HTTP request body and the following schema
{
"type": "object",
"properties": {
"token_type": {
"type": "string"
},
"scope": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"access_token": {
"type": "string"
},
"refresh_token": {
"type": "string"
}
}
}
Add the Body from the dynamic content from the HTTP – GET Token action to the content of the Parse JSON action
Include the access token from the Output of the Parse JSON action when calling the Microsoft Graph API on the Headers sections as shown below
To get the users events from the default calendar
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/calendar/events
Method 2:
You can also make a request to Graph API using the Active Directory OAuth Authentication under the advanced options of the action as shown below
My other blog post to call Microsoft graph API in Power Apps and Power Automate using a custom connector
Summary: I have written a blog to get the attendee details of a meeting using this approach to Microsoft graph event endpoint API. Hope you have found this informational & thanks for reading. If you are visiting my blog for the first time, please do take a look at my other Microsoft graph in Power Automate blogposts in my blog site.
Top comments (0)