PowerApps – Call Microsoft Graph API in Canvas App

Introduction

Hello Everyone,

Hope you all are doing great and staying safe!

Today, in this blog I am gonna share PowerGuideTip23, where I\’ll show you a way to call Microsoft Graph API in Canvas App. This article is also helpful for all those folks, who are looking for a Step by Step guidance to call Custom Connector in PowerApps.
If you are yet to know the fundamentals of Microsoft Graph API. Please check my this article first.
There are many business requirements, where you need to collect information about Logged In-App users from Azure Active Directories like User\’s Security Roles, Security Group, License, Profile details, and much more. Apart from collecting information from Azure AD, you may also need to perform operations in Microsoft Teams, Office 365, SharePoint, and many other applications as well directly through Canvas App.
Let\’s get started and check how to use Microsoft Graph API in your Canvas App.
Prerequisites –
  • Azure Subscription (Trial is also fine)
  • Global Admin rights on Azure AD.
  • PowerApps License (Trial is also fine)
  • Graph Explorer to test the Microsoft Graph API.
Implementation

Azure AD App Registration
Step 1 – Open Azure Portal.
Step 2 – Click on Manage Azure Active Directory > View.
Step 3 – Select the App registrations option from the left panel and click on the + New registration
button to register a new application.
Step 4 – Provide the Name of the application \”PowerAppsConnectorApp\” and click on Register.

Step 5 – Copy the Application ID for later use.
Step 6 – Generate a Secret Key and Copy it for later use
Step 7 – Configure API Permission to call Graph API and perform the operation in Azure AD.
Step 8 – Hit Grant admin consent. You need to have the appropriate rights (Global Admin) to perform this action. 

Create a Custom Connector in PowerApps to call Graph API
Step 1 – Open PowerApps Creation Page. Click here
Step 2 – Expand the Data section and Click on Custom Connectors from the left panel.
Step 3 – Click on + New Custom Connector and select Create from blank.

Step 4 – Provide the Name of the Connector and hit Continue.

Step 5 – Provide the Connector details in 3 sections (General, Security, and Definition) as per below
General Section

Security Section
Definition Section

In the Operation ID section, we need to provide the operation/function name that we will call from the canvas app to get the API response.

Click on Import from Sample > Choose Get Method > Paste the Graph API URL > Hit Import (as shown below)
Since, In this demo I want to retrieve only logged in powerapps user information from Azure AD, Hence, I have used /V1.0/me/. You can change the API URL as per your business need.
Same for the API Response. Click on + Add default response and paste the Response JSON (copied from Graph Explorer above) under the Body section (as shown below). And then Hit Import
Step 6 – Hit Create Connector
Step 7 – Navigate back to Security and copy the Redirect URL. 



Step 8 – Go to Azure Portal > Open your App > Click on Redirect URI > Click on + Add platform  > Select Web > Paste the URL > Click on Configure

Step 9 – Test the Connector
You must get the same response as Graph Explorer.

Create a Canvas App and use the Custom Connector

Step 1 – Create a new Canvas App or can open your existing app as well.
Step 2 – Add a Blank screen and some Text Input controls and one Button as per below
Step 3 – Go to View > Data Sources and Add our Custom Connector in the App.
Step 5 – Add the formula to call custom connector on OnSelect property of the button.
UpdateContext({UserProfile:PowerUserConnector.getmyuserdetails()})  

In this formula, I have captured the response returned from the Graph API in a Local Variable (UserProfile), so that later, I could use it to set the value in Text Input Controls.
Step 6 – Set the value in Text Input controls retrieved from the Custom Connector.

Test & Demo


Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

11 thoughts on “PowerApps – Call Microsoft Graph API in Canvas App

  1. Thanks for your needful blog post about Microsoft & I hope this will be the helpful topic for beginners. Well, I am also following some post like this and the persons who have more knowledge about this and its proper implementation. One of them AdyatanTech is very good platform as per my point of view. So I must say all to follow some popular posts with superb ideas to improve their business.

    Like

  2. Earlier this year, Apple released its list of top iPhone Elyments App at the one billion download mark. It's a very interesting list and there are a lot of good lessons to be learned from it and a lot of money to be made, if you can get it right. How to get access to this giant cash cow? Here are some tips, based on our analysis of Apple's twenty top paid apps.

    Like

  3. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! flexispy reviews

    Like

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 )

Google photo

You are commenting using your Google 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

%d bloggers like this: