<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohamed Ashiq Faleel</title>
    <description>The latest articles on DEV Community by Mohamed Ashiq Faleel (@ashiqf).</description>
    <link>https://dev.to/ashiqf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F411409%2F8b7b704d-0aef-4b37-b0ee-e0923fa9aa07.jpeg</url>
      <title>DEV Community: Mohamed Ashiq Faleel</title>
      <link>https://dev.to/ashiqf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashiqf"/>
    <language>en</language>
    <item>
      <title>Call Microsoft Graph API  with application permission from Power Automate using HTTP connector</title>
      <dc:creator>Mohamed Ashiq Faleel</dc:creator>
      <pubDate>Mon, 22 Mar 2021 09:40:54 +0000</pubDate>
      <link>https://dev.to/ashiqf/call-microsoft-graph-api-as-a-daemon-application-with-application-permission-from-power-automate-using-http-connector-4082</link>
      <guid>https://dev.to/ashiqf/call-microsoft-graph-api-as-a-daemon-application-with-application-permission-from-power-automate-using-http-connector-4082</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Requisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Access to HTTP Premium Connector in Power Automate&lt;/li&gt;
&lt;li&gt;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 &amp;amp; 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vL2qAef7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyqkfqf1b8q8zzvdpv98.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vL2qAef7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyqkfqf1b8q8zzvdpv98.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is not required in the Azure AD application to have a redirect URI.&lt;/p&gt;

&lt;h1&gt;
  
  
  Power Automate Flow:
&lt;/h1&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  To generate a token
&lt;/h3&gt;

&lt;p&gt;Store the Client Secret on a String variable&lt;br&gt;
Make a HTTP request using the HTTP connector with the following details. Make sure to replace the string for tenantId, azureAdAppclientId and azureAdAppclientSecret&lt;/p&gt;
&lt;h1&gt;
  
  
  Method 1:
&lt;/h1&gt;

&lt;p&gt;Add a HTTP connector action to the flow for making a POST request per the following information&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;: POST&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;URI&lt;/strong&gt;: &lt;a href="https://login.microsoftonline.com/yourtenantId/oauth2/v2.0/token"&gt;https://login.microsoftonline.com/yourtenantId/oauth2/v2.0/token&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Headers&lt;/strong&gt;: Content-Type: application/x-www-form-urlencoded&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Body&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Replace the tenantId, client id and client secret from the variable&lt;/p&gt;

&lt;p&gt;tenant=yourtenantId&amp;amp;client_id=azureAdAppclientId&amp;amp;client_secret=@{decodeUriComponent(variables('azureAdAppclientSecret'))}&amp;amp;grant_type=client_credentials&amp;amp;scope=&lt;a href="https://graph.microsoft.com/.default"&gt;https://graph.microsoft.com/.default&lt;/a&gt;&lt;br&gt;
For the client secret make sure to URL encode using the expression &lt;strong&gt;encodeUriComponent(variables(‘clientSecret’))&lt;/strong&gt; else the request will fail due to the presence of special characters.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aw-US9qV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22cyhuagz61x0g9fgzlz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aw-US9qV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22cyhuagz61x0g9fgzlz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
To extract the token from the above request, add the parse JSON action with Content from the HTTP request body and the following schema&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
    "type": "object",&lt;br&gt;
    "properties": {&lt;br&gt;
        "token_type": {&lt;br&gt;
            "type": "string"&lt;br&gt;
        },&lt;br&gt;
        "scope": {&lt;br&gt;
            "type": "string"&lt;br&gt;
        },&lt;br&gt;
        "expires_in": {&lt;br&gt;
            "type": "integer"&lt;br&gt;
        },&lt;br&gt;
        "ext_expires_in": {&lt;br&gt;
            "type": "integer"&lt;br&gt;
        },&lt;br&gt;
        "access_token": {&lt;br&gt;
            "type": "string"&lt;br&gt;
        },&lt;br&gt;
        "refresh_token": {&lt;br&gt;
            "type": "string"&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Add the Body from the dynamic content from the HTTP – GET Token action to the content of the Parse JSON action&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xBm_M0SW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2341awhmpjjwyqu7hc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xBm_M0SW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2341awhmpjjwyqu7hc8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
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&lt;/p&gt;

&lt;p&gt;To get the users events from the default calendar&lt;/p&gt;

&lt;p&gt;&lt;a href="https://graph.microsoft.com/v1.0/users/%7Bid"&gt;https://graph.microsoft.com/v1.0/users/{id&lt;/a&gt; | userPrincipalName}/calendar/events&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YS5uAO2I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7lx82f5vxbod06hg2lc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YS5uAO2I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7lx82f5vxbod06hg2lc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Method 2:
&lt;/h1&gt;

&lt;p&gt;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&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---SScL4Kq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsu3pmweoux4xhgjeu95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---SScL4Kq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsu3pmweoux4xhgjeu95.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
My other blog post to call &lt;a href="https://ashiqf.com/2021/03/16/call-microsoft-graph-api-in-power-apps-and-power-automate-using-a-custom-connector/"&gt;Microsoft graph API in Power Apps and Power Automate using a custom connector&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: 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 &amp;amp; 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  &lt;a href="https://ashiqf.com"&gt;blog site&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
