Pattern & implementation for making long Async Http calls in Microsoft Flow : (part 1 : polling)

I very much like the MS Flow Http action and I use it all the times for calling the Microsoft Graph, calling Azure function, calling other flows,…

But last year, as illustrated in my blog post I ran across a scenario where my flow had to provision a site collection and to apply PnP site templates; this could take several minutes; the provisioning itself was implemented in an Azure function posting a message in an Azure Queue, and listening to this queue, because the Http ran in timeout after 2 minutes. It worked pretty well, but I find that too complex.

This morning I ran across the following blog post from Derek Li (Azure team) that illustrates how to implement a long running async call with Logic Apps. Read this post first and come back here. He solved the issue by implementing a Web Management api policy that we cannot leverage in Flow. Read his post again ;-).

But I couldn’t find any example of this with flow, so here we are.

Now how can we implement this async polling pattern in Flow ?

I’ve created the same long running service Flow (that returns ‘hello world’ after 150 seconds (an Http call timeouts after 120 seconds). This also works with Azure functions, status code 202 is quite common in the industry.

As far as I know, we cannot use the Web API Management policy in Flow as illustrated in Derek post (we can still export our flow as a logic app JSON application though), but the idea is :

  • Set the called flow Request action to async mode
  • Create the first HTTP Call
  • Check if the status code is 202, which means the called flow will be a long running oneand is…working on it 😉
  • If status code is 202 save the endpoint url in a variable
  • Loop and call the endpoint (second HTTP call) until we get a 200 code

Here is my called Flow:

async1

The Response Action has been set to async:

async2

Here is my Caller Flow :

asynccallerflow

Getting the status code after the first Http call is easy : I’ve used the expression actionOutputs(‘HTTP’)?[‘Headers’]?[‘StatusCode’]

getstatuscode

retrieving the EndPoint url was also easy with the expression : actionOutputs(‘HTTP’)?[‘Headers’]?[‘Location’]

endpointurl

The second Http call invokes the endpoint url :

endpointurl

…and you won’t believe it but that works :

hello

see part 2 (HTTP webhook action)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s