Power Platform – Pass external API collection from Power Automate to Canvas App
In this article, lets see how to pass an external API’s json collection from Power Automate(Formerly ‘Microsoft Flow’) to a Canvas application.
For this example, I am going to use ESRI mapping service API, in my Power Automate Flow. Refer here to know more about ESRI. You may also use other APIs as per your convenience.
ESRI API is url based and returns the ‘Address Suggestions’ in json format.
Before we start lets make sure to meet all the prerequisites.
Prerequisites:
- Subscribe to 30 days trial and get Office 365 account.
- Connect to Power Automate portal using Office 365 account to build Power Automate flow.
- Connect to Power Apps maker portal using Office 365 account to build the Canvas App.
- ESRI api URL – Refer my previous article on the usage of ESRI or you can simply use this url
Once all prerequisites are met, here is the high level design:
- Create a new Power Automate flow and call ESRI API to fetch Address Suggestions.
- You can take any open API which returns json collection.
- Parse the ESRI API Response to json collection.
- Create a new Canvas app
- Trigger Power automate flow from Canvas App and read the collection.
Lets get started.
Steps to configure the Power Automate Flow:
- Connect to Power Automate portal
- Create a new ‘Instant flow’ by selecting the right Environment.
- Provide a name ‘GetAddressSuggestions’ and select trigger as ‘PowerApps’
- To call ESRI api, add a new ‘HTTP’ action.
- Choose Method as ‘GET’ and in URI paste the ESRI url as mentioned in prerequisite section.
- Next, we need to parse the response from ESRI api. As the ESRI results would be in json format, add ‘Parse JSON’ action.
- In ‘Parse JSON’ action,
- set Content as ‘Body’ from HTTP action.
- Next we need to provide the json schema of ESRI response. To do that, click on ‘Generate from sample’.
- Now copy the response from ESRI API (Copy the browser’s output using ctrl+a+copy)
- Paste in the ‘Insert a sample JSON Payload’ window and click ‘Done’.
- If no warnings, your ‘Parse JSON’ pane should look as below.
- As we completed the ESRI response capture and parsing to json, now we need to pass the captured json response to Power App.
- To pass the json response to Power App, add a new ‘Response’ action.
- In the ‘Response’ pane,
- Set the ‘Body’ to ‘Body’ from ‘Parse JSON’.
- Expand ‘Show advanced options’ and click on ‘Generate from sample’.
- Copy the response from ESRI API and paste in the ‘Insert a sample JSON Payload’ window and click ‘Done’. (Same step like we did in ‘Parse JSON’ pane).
- ‘Response’ pane should look as below with no warnings.
- Run the flow and make sure it ran successfully.
Steps to configure the Canvas App:
As we completed the Power Auto Flow, now its time to consume the Power Automate flow response from Canvas App by following the steps below
- Connect to Power Apps maker portal using the same Office 365 account.
- Create a new Canvas App.
- Note: Make sure the same Environment used for Power Automate is selected.
- Add a new button.
- Select the button, from the ribbon menu, click on ‘Action -> Power Automate’.
- From the pane select the ‘GetAddressSuggestions’ Power app flow.
- After few seconds, you would see the Run() command auto populated as below.
- As we going to get json collection from flow, lets capture the json collection to a collection variable ‘collAddress’ using ‘ClearCollect()’. Refer article to know more about ‘ClearCollect()’.
- With the ClearCollect() and Run() functions, the final ‘OnSelect’ statement should look as below.
- Lets run the App and click on the button. Application takes couple of minutes to complete the run.
- Post run, check the collection returned from flow by going to ‘File -> Collections’ tab.
- You can also add a ‘Data table’ control and display the results returned from flow as below
🙂
Hi Rajeev,
Is there a way to pass JSON object from model driven app to Canvas app as query string Parameter and need convert that as collection to display in Gallery/Table format
https://apps.powerapps.com/play/54709-13-4154-835e-1889bb6c3742?source=modelDrivenApp&screenColor=rgba(239,243,246,1)&CID=3&result=%5B{‘Scored Probability of High Risk:0.25},{‘Scored Probability of Medium Risk’:0.25},{‘Scored Probability of Low Risk’:0.50}, {‘Scored Labels’:’Low Risk’}}
Thanks & Regards,
Nandhini M