How to build nested flows with the HTTP action

Step 1: Modelling your workflows

In this walkthrough I would like to create a common approval process for files added in two different places. A flow's trigger can only listen to one location at a time, so there's no way to build a single flow that can listen to many different locations. Instead, I can use a nested workflow that has all the approval logic, and call it from two different workflows — each of which listen to their respective location. To have one flow call another flow I will use the HTTP action.

Here is a diagram showing the overall design:

It's important to know what information will be sent from the parent flows to the child flow. In this case, I just need the name and link to the files. This will be sent in a JSON object that looks like:

{ "name" : "MyFile.docx", "link" : "https://microsoft.sharepoint.com/....MyFile.docx" }

Step 2: Create your nested / child workflow

Second, you'll have to create the flow that runs inside the others. In order to have a flow that can be called by other flows, you will need to start with the Request trigger. This trigger exposes an HTTP endpoint that can be called to kick off the flow.

In this trigger you should define the request payload. This payload is how the rest of the flow will know what fields it can use from the trigger. Select Use sample payload to generate schema and then paste in the JSON object from Step 1.

Now you can construct the rest of the flow that you want to be shared. In this case, I'm going to build an Approval flow for the documents. When I fill out the approval actions, I can use the fields that were passed in from the trigger:

Finally, Save your child flow and copy the HTTP POST URL from the request trigger (you'll use this in the next step).

Step 3: Call the child workflow from the parent flows

Third, you'll need to build your parent workflows that call into the child workflow. Start with the trigger you need, just like any other flow. Then, add an HTTP action. Select the POST method and paste in the HTTP Post URL you copied from Step 2. 

Last, you will need to include in the Body the JSON object that you defined in Step 1. Be sure to replace the placeholders with dynamic content from the trigger (as I did above with File name and File path). Now you can repeat this same process with the other Parent flow, calling the same HTTP endpoint. 

Summary

In three steps you can build a single workflow that can be called by other workflows. Other scenarios for nested workflows include a flow that you want to run on a schedule AND based on some trigger (for example, generate a report when there is new data, and once a day), or, for handling nested loops. Since Microsoft Flow limits you to one apply to each loop at a time, you can call into a child workflow that has its own apply to each — if you need to process arrays inside of other arrays. I hope you found the walkthrough helpful, let us know what questions you have on the Flow Community.