Rest API calls with PowerApps
Asked Answered
C

2

13

I am playing around with Microsoft PowerApps and Microsoft Flow. I am trying to figure out how to make API calls from PowerApps and return the results(Status and Body) to a field such as a text box in my app.

I can make the HTTP requests through Flow and put them in a static file such as an excel spreadsheet...etc. I can also make the calls from a PowerApps control such as a button but all I know how to do with it is return it to something like an excel file, when really I want to return it to a Text Box or Text Area.

Cadent answered 12/5, 2016 at 19:54 Comment(0)
A
10

Today you cannot access the raw HTTP status/body from a PowerApp. The way to call "arbitrary" HTTP endpoints is to use Custom APIs that you can describe using Swagger. I wrote a quick blog on how to call Azure functions that shows how to craft a swagger to call the API: https://powerapps.microsoft.com/en-us/blog/using-azure-functions-in-powerapps/

Might be good if you could clarify the specific scenario you are trying to build to see if there are other ways, but one option that comes to mind is to build a custom API that receives the URL and on the server-side performs the HTTP request and returns the values in an object that then you can easily access in PowerApps.

Aletheaalethia answered 4/6, 2016 at 17:33 Comment(1)
you need to use microsoft "FLOW" to call the rest web service "HTTP" Action and return the response to PowerApps. In flow both trigger and action will be powerapps and respond to powerapps.Wainscoting
W
7

It is relatively straightforward to visualize API (JSON) responses using a PowerApps Gallery Control.

Do this:

  1. Ensure the Flow has the correct JSON response before proceeding
  2. Add ClearCollect(colResponse, myFlow.apiRequest()) Function to a Button Control in the PowerApp
  3. Execute the API call (click the button)
  4. Inspect colResponse (View/Collections) to ensure it has content
  5. Insert a blank Gallery Control
  6. Set its Items Property to colResponse
  7. Insert a TextBox Control into the Gallery
  8. Set its Text Property to ThisItem.<someColumn>

Depending on the shape of your JSON response (flat or nested table), you may have to do some wrangling.

There are 3 areas to focus your wrangling:

  1. On the ClearCollect Function.

a. Add some dot notation to the end of this to "dig" into the API response before it hits the Gallery Control

b. Example: ClearCollect(colResponse, myFlow.apiRequest()).someColumn

  1. On the Gallery Control Items Property

a. Add some dot notation to the end of colResponse to "dig" into the Collection

b. Example: colResponse.someColumn

  1. On the TextBox Control within the Gallery

a. Add the First() Function to the Text Property

b. Example: `First(ThisItem.someColumn).someColumn2'

c. Note: There are some JSON schemas that require MULTIPLE First()'s to "dig" into the correct level. First(First(ThisItem.someColumn).someColumn2).someColumn3 etc.

See this video for tips on visualizing API responses in PowerApps Galleries.

Worser answered 21/7, 2019 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.