There are over 400 connectors to connect Power Apps to almost every conceivable service, database or back end. This article is how to connect to end points that don’t have a custom connector or custom purpose-built Azure functions. The documentation does a great job of walking through creating an Azure Function. https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp. This walk through will assume you have followed these directions to create an Azure Function -and start from there.
Select the Azure Functions extension for Visual Studio Code and add a new function using the lighting bolt glyph.
In this example we have named the function “SydneyWeather”
In this example we have used the name “Getweather.Function”
Since this is a demo, set the access to anonymous.
In this lab is updating the function created earlier in the https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp lab.
(Not this is for demo purposes only, normally one would not check in directly to a production site)
In this example the function was deployed to a function with the name “GetTemperature” therefore can be called using the following URL
https://gettemperature.azurewebsites.net/api/Sydneyweather
This returned the following:
“This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.”
If a query string is passed in like the following:
https://gettemperature.azurewebsites.net/api/Sydneyweather?name=Chuck
Will return the following:
“Hello, Chuck. This HTTP triggered function executed successfully.”
While Azure Functions extension for Visual Studio Code makes it easy to create an HTTP based function the default template returns a string, it does NOT return JSON…So these functions this can be called from a Flow in Power Automate, Power Apps requires all connectors return JSON.
Click on the files view of Visual Studio code and the SydneyWeather function
Comment out the template return and paste in the following code:
//return new OkObjectResult(responseMessage);
var myObj = new {name = “Mostly Sunny”, location = “Sydney”};
var jsonToReturn = JsonConvert.SerializeObject(myObj);
return new OkObjectResult(jsonToReturn);
This should look like the following image:
Running the updated browser will now return the following JSON
Congratulations your Azure function is now ready to be called by Power Apps!
Change the verb to “Get” and past in your function URL….From the example above it would be:
https://gettemperature.azurewebsites.net/api/sydneyweather
Then click impot
Using the browser run response, paste in the response to the body and select import. In the example above it would be:
{"name":"Mostly Sunny","location":"Sydney"}
Add a button and set the text of the button to the custom connector name, namespace and function name.
In this example it would be:
SydneyWeather.SydneyWeather().name
Congratulations you have created an Azure function, a custom connector and called them from Power Apps!