Search code examples
powerappspowerapps-formula

Use a value from an API in Powerapp


I have an API to perform a calculation

myapi.calc(int, int)

that returns another integer

I want to display that integer in a PowerApp field (really I want to do something useful with it, but for the moment displaying would be a breakthrough)

when I put the formula myapi.calc(100,100)I get an error of 'Behavior function in a non behavior property'

So I am obviously doing something horribly wrong, but I haven't got a clue what I am missing.

Any thoughts?


Solution

  • Just some instructions here on how to create a custom connector - in case you haven't already

    One way of doing that would be to create a Custom Connector steps on how to create from scratch

    • (Side Menu) Data -> Custom Connectors -> (Top bar) "+ New custom connector"

    You will have some option e.g Create 'From Blank', 'Azure' or Import 'From OpenAPI', 'Postman'

    Once you have your connection created and tested, you will be able to add that to your Power App

    MyApi.MyAction({"Parameters"})
    

    Store that in a collection or variable

    ClearCollect(returnedValuesCollection, MyApi.MyAction({"Parameters"}).documents.value)
    

    Another way of doing it would be to trigger a flow (Power Automate) from Power App and perform your API call in the flow and then return that value to Power App.

    Steps from Power Automate:

    • Add a Power Apps trigger
    • Add more actions to the flow and choose the option "Ask in Power Apps" - that will give you the ability to parse parameters from Power Apps to Flow
    • Add HTTP request call and manipulate the results (JSON for example)
    • Add a return to Power Apps action in flow. Save the flow

    Steps from Power Apps

    • Select an object (Button) and go to the OnSelect Property
    • In the Action tab, click Power Automate and choose from a list of flows the one you just created.
    • You will see 'Your flow name'.Run(parameter1,parameter2,...)
    • You can wrap that in a variable and use Set(myFlowReturn,'Your flow name'.Run(parameter1,parameter2,...)) -> myFlowReturn.ValueFromYourAPI