Exposing your Azure API App to PowerApps and Flow

Since some time Azure allows you to expose your API apps to PowerApps and Flow in an easy way. Just go to your API definition (make sure CORS is enabled) and click on the export-button.

Capture0

This gives you a dialog where you can download or get a link to your Swagger metadata-file. Download it, and click on Go To PowerApps or Flow.

Capture

Importing into PowerApps is the simplest to do.In the PowerApps page, select Connectors, custom and then New Custom API. Just link to your swagger file and click next.

Capture1

There you go. Flow needs a little bit more work.Go to the Custom APIs for Flow and add a custom API. Again, link to your swagger file.

Capture2

The extra work is that you can (and probably should for improving usability) provide more information for each of your API functions.

Capture5

After you've done, start using it in flow and powerapps.

Creating connectors for your Logic Apps/Flow (Part 3 – More triggers)

So, let's recap: we had regular connectors, we had poll triggers. So, we're still missing the push triggers. A poll trigger needs to be polled regularly by the logic app to see if it can continue. A push trigger does not have to be polled, it will tell the logic app when it needs to continue, passing the necessary information. At this moment a push trigger needs to be called by a webhook-action. Your trigger needs two function : Subscribe and Unsubscribe. In the Webhook-action these functions will automatically be called when the Logic App starts or stops. The WebHook action needs to pass the callback-url to your Subscribe/Unsubscribe-action. This callback-url is the url your API app will call for starting the Logic App. Your functions should look like this :

public static List subscriptions = new List();
[HttpPost, Route("api/webhooktrigger/subscribe")]
public HttpResponseMessage Subscribe([FromBody] string callbackUrl)
{
    subscriptions.Add(callbackUrl);
    return Request.CreateResponse();
}
[HttpPost, Route("api/webhooktrigger/unsubscribe")]
public HttpResponseMessage Unsubscribe([FromBody] string callbackUrl)
{
    subscriptions.Remove(callbackUrl);
    return Request.CreateResponse();
}
The idea is that you call back the logic apps using the list of subscriptions as this:
using (HttpClient client = new HttpClient())
{
    foreach (string callbackUrl in subscriptions)
        await client.PostAsync(callbackUrl, 
            @"{""trigger"":""fired""}", 
            new JsonMediaTypeFormatter(), "application/json");
}

After this your Logic app continues.

For using the pushtrigger you need a webhook-connector in your logic app. This needs to call the subscribe and unsubscribe-methods of your API App. For the body you need to pass the callback url.

 image

 

But still it won't work. When going to the Trigger History you can find that you get a failure because of an error with the content-Type. It is simple to solve: Show the advanced options of your webhook-connector and add the content-type to your subscribe- and unsubscribe-headers as this:

image

Problem solved !