Flow – Http Request – Split On Collection

A use case I like with to use with Flow and Logic Apps is to create a workflow triggered by a Http Request that acts as an API endpoint. In a previous post I explained how to do it and how to configure Flow to the validate the Json payload. In that post the Json request was just a simple contact object with a few data fields that we inserted into Dynamics 365.

Did know you can also create a Flow Http Request to accept an array of JSON objects? You can then use the Split On option to fire the workflow for each object in a collection like the one below I used in this example.

{
“contacts”: [
{
“contactid”: 1,
“firstname”: “Thelma”,
“lastname”: “Barton”,
“email”: “louis@siegel.mg”
},
{
“contactid”: 2,
“firstname”: “Meredith”,
“lastname”: “O”,
“email”: “marshall@kenney.gl”
},
{
“contactid”: 3,
“firstname”: “Marcus”,
“lastname”: “Gross”,
“email”: “lori@owen.ax”
}]}

You create your Http request Flow inthe usual manner and either use a Json schema or some sample JSON with an array of of objects to generate the endpoint and schema. You can process the collection of received objects by using the “Apply to Each” control to iterate over the collection and execute actions. Below we are looping over the array of contact objects and inserting a record in a database for each one.

Flow - Http Request - Split On Collection Joe Gill Dynamics 365 Consultant
Microsoft Flow – Apply To Each

Having used Postman to call my Flow endpoint with an array of 100 contacts records I can now examine the Flow run. If any of the actions in the loop fail then the run will have failed and you can inspect the run to view individual sucessesfull and failed actions.

Flow - Http Request - Split On Collection Joe Gill Dynamics 365 Consultant

When you use process a collection like this it can be it can makes things hard to manage if you are reprocessing a large number of objects or have long running or complicated workflow. So rather than loop over the objects in your Flow you use the Split On option to split the array of Json objects and fire the workflow for each object. Goto to Setting on the Http Request trigger and turn the Split On option on and enter the name of the array you want to split on.

Flow - Http Request - Split On Collection Joe Gill Dynamics 365 Consultant

If you use Split On then you no longer need the Apply to Each in your flow

Flow - Http Request - Split On Collection Joe Gill Dynamics 365 Consultant

Now when I submit the collection of objects they are spilt into individual flow runs that I can view and resubmit as required.

Flow - Http Request - Split On Collection Joe Gill Dynamics 365 Consultant