Adventures with Logic Apps: Logic Apps Calling Logic Apps

Logic Apps

There are several articles available on how Logic Apps can call other Logic Apps. Most of the examples I found were larger in scope or overly complicated, geared towards specific business cases.

I wanted a simple example, but one that was robust enough that would lead to great learning experience.

So let’s get started.

Create Azure Resources

We first need to create a resource group.

I called mine mjr-###-rg, where ### is just a three digit number that makes it easy for me to name resources within in Azure, because if I had to give it a real name, I would be stuck hear forever.

After the resource group is created, we want to create three Logic Apps, a parent Logic App and two child Logic Apps.

Navigate to Logic Apps in the Azure Portal.

Click Add.

Enter a Name for your Logic App, I called mine mjr-###-001-logapp.

For the Logic App, set the Resource Group to the resource group we created earlier in this article, I set mine to mjr-###-rg.

Add two more Logic Apps, these will be the child Logic Apps. I called mine mjr-###-001-A-logapp and mjr-###-001-B-logapp.

Sit tight, might take a couple of minutes for the Logic Apps to be created.

While you are waiting, let’s talk about what this is going to look like when we are done?

The parent Logic App will be created as a Request trigger, so we can test it with Postman.

The parent Logic App will hold an Array variable called message, and as it calls each child Logic App, it will append the message property in the response from the child Logic App to the Array variable message.

One thing to call out, as far as I can tell, only Request triggers, specifically When a HTTP request is received trigger, can be called by other Logic Apps.

The parent Logic App will return a response that contains the Array variable message.

If successful, we should receive a response with a message property that contains a message for each Logic App that was called, both the parent Logic App and the child Logic Apps.

Build the Child Logic Apps

Navigate back to the Logic Apps and click on the first child Logic App, e.g. mjr-###-001-A-logapp.

From the Logic App blade, under Development Tools, click Logic app code view.

Paste the contents of the gist located at https://gist.github.com/mattruma/94626301b30dd0d1db15c2c19a5aec6a.

Replace the text YOUR_LOGIC_APP_NAME with the name of your child Logic App, e.g. mjr-###-001-A-logapp.

Click Save.

Repeat for the other child Logic App, e.g. mjr-###-002-B-logapp.

Build the Parent Logic App

Navigate back to Logic Apps, and Select the parent Logic App, e.g. mjr-###-001-logapp.

From the Logic App blade, under Development Tools, click Logic app design view.

Select a Request trigger.

Then select When a HTTP request is received trigger.

Click Save.

This will generate the HTTP POST URL so we can test the Logic App from Postman.

Click New Action.

Search for Variables and select Initialize variable.

Set the Name to Message.

Set the Type to Array.

Click in the Value field, a dialog should appear to the right.

Select the Expression tab and paste createArray('YOUR_PARENT_LOGIC_APP_NAME received your request.') into the expression and click OK.

Replace YOUR_PARENT_LOGIC_APP_NAME with the name of your parent Logic App.

Click Save.

Now we will call our child Logic Apps from the parent Logic App.

Click New step.

Search for Logic Apps and then click on Choose a Logic Apps workflow.

Select your child Logic App, e.g. mjr-###-001-A-logapp.

Select the manual action.

Click Save.

Click New step.

Search for parse JSON.

Select the Parse JSON action.

Click in the Content field and then select the Body from the displayed dialog for the child Logic App.

In the Schema field paste the contents of https://gist.githubusercontent.com/mattruma/f9c5f8161cfffb5e64741dd984c75962/raw/50af78c85e97725ab1e78e4c6639a89dfd667b2f/sample-1-child-logic-app-schema.

Click Save.

Click New step.

Search for Append to array.

Select the Append to array variable action.

Select Message for the Name.

Click the Value field.

From the dialog, select message from the Parse JSON action.

Click Save.

Click New step.

Search for Response.

Select the Response action.

In the Body field paste { "message": @{variables('Message')} }. This returns the current value of the Message variable to the caller.

Click Save.

Let’s test the parent Logic App.

Copy the value of the HTTP POST URL field in the trigger of the parent Logic App.

Open up Postman and create a new request.

Paste the HTTP POST URL into the request URL and change the call to a POST.

Click Send.

The response should contain an array of all the messages in the message property.

If you want the parent Logic App to also call the other child Logic App we created you will want to navigate back to the designer for the parent Logic App.

Hover over the connector right after the Initialize variable action.

Click the plus sign.

Click Add a parallel branch.

For this branch repeat the steps we executed for the first child Logic App, calling the child Logic App, parsing the JSON and appending the message to the Message variable.

I will wait right here until you are completed.

To bring together these branches into a single Response we are going to want to delete the current Response in our parent Logic App.

Click New step.

Then recreate the Response just as we did before.

Notice the Response action is dependent on both our child Logic Apps completing before sending the response to the user.

Click Save.

Resend the request in Postman.

You should now see messages from both our child Logic Apps.

Wrap Up

Granted, this is an academic example, but it really helped me get a handle on Logic Apps calling other Logic Apps.

Hope this helps you, and as always, appreciate any feedback!


Discover more from Matt Ruma

Subscribe to get the latest posts sent to your email.

1 Reply to “Adventures with Logic Apps: Logic Apps Calling Logic Apps”

  1. Hi Matt ,

    I am trying something very similar and your blogpost was really helpful. However i have a question. If my child has to return a array of values to the parent , should i mention the json schema in the parent or in the child.

    Now my logic app has a loop step which takes a lot of time. So i decided to split it into parent and child( child should handle the looping). The parent has the header item schema. Should i break the schema and place header in parent and item in child?.

Leave a Reply

Your email address will not be published. Required fields are marked *