In this article, I’ll explain how you can create Custom Connector for the Microsoft Graph API in Power Apps.
Overview
Connectors enable logic app to integrate with the data and business processes. There are many pre-built connectors available for this purpose. Sometimes you may want to integrate with APIs, Services and Systems that are not available as pre-built connectors. To support this situation, we can create custom connectors with our own triggers and actions. All these connectors are function-based, which means that data will be returned based on calling specific functions in the underlying service. Custom connectors are essentially wrappers for Restful APIs, which allow basic services to communicate with logic apps. Therefore, even before creating a custom connector, you need Restful API.
Register Azure AD Application
- For registering Azure AD application, you must have an azure account with an active subscription and azure AD tenant.
- Sign-in to the https://portal.azure.com with an account that has permissions to make Azure Active Directory applications.
- To register an application, select Azure Active Directory and select App registrations and select + New registration. Enter Application Name, select a supported account type, which will decide who may use the application and select Application type Web and enter Sign-on URL (e.g.: https://localhost/customconnector) under Redirect URI. Click Register after setting the values.

- After registering Azure AD application, copy Application(Client Id) and save it.
- To add client secret, select Certificates & secrets and click on New client secret enter Description and select duration from the Expires list and click Add. After adding client secret, copy client secret and save it
- Select API permissions for granting the delegated permissions your application needs to interact with the MS Graph API. Select Add a permission, select Delegate permission and add Directory.Read.All and Group.Read.All delegated permissions.

- After adding permissions provide admin consent by Clicking on Grant admin consent.
Create Custom Connector
- Sign-in to Microsoft graph explorer using https://developer.microsoft.com/en-us/graph/graph-explorer
- Either use method from Microsoft graph’s sample queries or directly enter URL. After that click on Run query. Copy URL and Response from Response preview tab

- Sign into the https://make.powerapps.com/
- Expand Data from the navigation tab then select Custom Connector and click on New custom connector and then select Create from blank from the list.

- Enter Connector name in pop-up.In General tab, enter icon background color, connector’s Description . Select scheme as HTTPS, host name as graph.microsoft.com and base URL as /

- Navigate to Security tab. Select OAuth 2.0 as the API. Select Azure Active Directory as Identity Provider. Enter Client id (The client or app id from Azure), Client secret(The client or app secret from Azure), Login URL as https://login.windows.net, Resource URL as https://graph.microsoft.com. Enter Directory.Read.All and Group.Read.All in Scope to grant permissions.

- Navigate to Definition tab, enter Summary, Description and Unique Operation ID.

- Click on Import from sample, select Get Method,enter URL (https://graph.microsoft.com/v1.0/groups/{group-id}/members) that you have copied from graph explorer and click Import

- Click on Add default response and enter the response that you have copied from graph explorer and click Import.
- Click on Create Connector and navigate to Security tab. Redirect URL will be generated. Copy URL.
- Navigate to your App Homepage in Azure Portal and click on Redirect URIs link
- Select Authentication from the left tab and click on Add URI and enter Redirect URL that you have copied to authenticate your connector and click Save.

- Now navigate to Test tab in power apps. Click on New connection to test your Action.
- A popup message will appear, click Create.
- Enter credential to authenticate
- After authentication your connection will be add to connection list select the connection. Enter input parameter for your operation and click Test operation.

- The operation return the same response as in graph explorer.
- Click Update connector.
- In your canvas application, Click Data Source then expand Connector and you can use your custom connector that you created like other data source just by adding it and calling action.

Conclusion
In this article, I explained how you can create custom connector to integrate Microsoft Graph API within Power app and using same method, you’ll be able to create custom connector to integrate any Restful APIs within Powerapp.
Comments