This post describes how to create a custom connector (API connector) to call the Azure APIM from PowerApps and Flows. This process is especially helpful to know when you would like to use the Azure APIM from a PowerApp and/or Flow and there is no connector available for the Azure APIM we wish to use.
Before creating custom connector in powerapps, the first step is registering your Azure APIM application in the Microsoft Azure Portal and keep the following security details handy in notepad
- Client ID
- Client secret
- Tenant ID
- Resource url
Let’s start step by step…
1. The first step is to export Swagger File(OpenApi 2.0) from Azure APIM of the API you wish to connect from PowerApps/Power Automate.
Create custom connector
2. In a web browser, open the PowerApps web app in Office 365
3. Click Data, then click Custom Connectors
4. Click the + New custom connector link
5. Select Import an OpenApi file
6. Select the JSON file you exported in the first step
7. Enter the custom connector name
8. Click Continue
9. Change icon, color and description if required under General Tab
10. Verify Scheme, Host and Base URL
11. Click Security tab
12. In the Choose what authentication is implemented by your API dropdown list, select OAuth 2.0
13. In the OAuth 2.0 section, in the Identity Provider dropdown list, select Azure Active Directory
14. In the Client id text box, enter the Client Id you saved to Notepad
15. In the Client Secret text box, enter the Client secret you saved to Notepad
16. In the Scope text box, enter the permissions you configured when you made the application (Directory.Read.All, Group.Read.All)
17. In the Resource URL text box, enter Client ID fot Backend App Registration i.e. https://global.consent.azure-apim.net/redirect
18. Click Definition
19. Change the Operation Id to a valid name format. In this case, we use SearchPerson
20. Set if any http header needs to be passed with request
21. Click Create connector
22. Click the Test tab
23. Click New connection
24. Click Create
25. Sign in to your Office 365 account
26. Test Search Person operation
Custom connector is added to your data sources now.
Using Custom connector inside App
Let’s use the newly created Custom connector now
1. Create a new canvas app
2. Goto Connectors under Data sources and click on newly added Custom Connector
After adding the new Datasource a new item would be visible under In your App section.
3. Now add one Text Input and one Button control and one Gallery on the screen
4. Select the button’s OnSelect function and write the code shown in the screen below
In the code below we are calling the newly added Custom Connector’s Search Person Operation and the result is being stored inside a Collection. This collection it the datasource for the gallery on this screen.
5. Run the app and enter some text inside text input.
All matching records would be displayed in the gallery with Name, Image and status.
The Power Automate platform gives users an unprecedented way of automating business processes without the need to have coding knowledge. The platform gives the user the ability to create powerful workflows and connect to external systems like never before.
In this blog, I explained to you how you can formulate your custom connector for Power Apps through a series of steps. If you have any confusion, questions or insights, leave a comment below!