Exposing Logic Apps using API Management | Serverless360
← Return To Home

How to Expose and protect Logic App using Azure API Management (Part 3) – Exposing multiple Logic Apps in a single API

Tags:  
Azure Logic Apps

It has been a while since I wrote about this topic. I didn’t finish this blog series for several reasons, and now, one year later, it is the right time to continue this story. In the first part of this blog series, I have explained how you can expose a Logic App in API Management. It is a straightforward and simple process. Microsoft did a great job on this user experience. But the main questions I want to address in the post are:

  • If we have one or more Logic Apps that we want to expose on APIM as an API, do we need to have several APIs with one operation? Or can we combine them in a unique API?
  • What about implementing a proper REST naming convention on these APIs? Is it possible?

The quick answer to these questions is: Yes, we can combine multiple Logic Apps in a unique API. And yes, it is possible to change the default configurations and implement a proper REST naming convention.

The scenario

Let’s imagine we have the following Logic Apps:

Logic Apps

And we want to expose them as a single API on Azure API Management called: BizTalk Alerts API with the following operations:

  • POST bts-host-instance-alert
  • POST bts-ports-alert
  • POST bts-suspended-instances-alert

The problem

If I try to expose/import all the Logic Apps that we want using the default process described in the first part of this series:

  • Access to your APIM on the Azure Portal.
  • And on the left menu, under the APIs section, click the APIs option.
  • Select the button + Add API just above the All APIs list available.
  • On the Add a new API panel, you will find several different options to add a new API to your list:
    • Select the Logic App option.
  • This will open a Create from Logic App form that will allow us with a few clicks to ingest our logic app configuration into APIM.
  • To do that, we need:
    • On the Logic App attribute, click on Browse and select the Logic App we want to expose from the available Logic App list inside our subscription that can be triggered using an HTTP based trigger like the Request trigger.
    • This will fill all the required fields with default values except for the API URL suffix you need to provide.
    • To finish, click the Create button.
  • After you have done that, the wizard will create one API exposing the Logic App under a POST operation called manual-invoke with the URL /manual/paths/invoke.

What happens is that by doing that, we will end up having three (3) different APIs with a single operation called manual-invoke with the same URL /manual/paths/invoke only having a distinct API URL suffix:

  • https://saspapimanagement.azure-api.net/a/manual/paths/invoke
  • https://saspapimanagement.azure-api.net/b/manual/paths/invoke
  • https://saspapimanagement.azure-api.net/c/manual/paths/invoke

logic app API management

And if you think that, maybe if I give the same API URL suffix that we provide on the first exportation, the wizard will be smart enough to add a new operation to an existing API, that will not going to happen

Create from Logic App

You will also not have the importation wizard on the + Add operation option inside an existing API. You have to do it manually.

importation wizard

This behavior is not what we want to archive. Neither is according to REST best practices. So, how can we improve this? How can we do better?

Exposing several Logic Apps as different operations inside API using REST best practices

To expose our 3 Logic Apps as different operations inside API using REST best practices, we will be going to start by using the default importation process:

  • Select the button + Add API just above the All APIs list available.
  • On the Add a new API panel, you will find several different options to add a new API to your list:
    • Select the Logic App option.

REST best practices

  • This will open a Create from Logic App form that will allow us with a few clicks to ingest our logic app configuration into APIM.

logic app API management

  • To do that, we need:
    • On the Logic App attribute, click on Browse and select the Logic App we want to expose from the available Logic App list inside our subscription that can be triggered using an HTTP based trigger like the Request trigger.
      • Let’s choose the first one, POCMonitor-BizTalk-Host-Instances, and click Select

Import logic app

      • This will fill all the required fields with default values, but we don’t want this configuration.

Create from logic app

      • Instead, let’s change to these values:
        • Display name: BizTalk Alerts API
        • Name: biztalk-alerts-api
        • API URL suffix: biztalk-alert

Create from logic app

      • To finish, click the Create button.

We now have a new API with the proper name, BizTalk Alerts API, but we still have a manual-invoke POST operation with the URL /manual/paths/invoke. Now the next step is to fix this configuration to have a proper REST best practice naming convention. And we can do this by:

  • Select the manual-invoke operation, and on the Frontend panel, select the Open form-based editor

logic app API management

  • On the Frontend editor panel, modify the following values and then select Save.
    • Display name: change from manual-invoke to host-instances-notification
    • URL: keep it POST operation but change the value /manual/paths/invoke to /host-instances/notification

frontend

Now we have our first Logic App exposed in API Management with a proper naming convention. You can go ahead and try it.

To add the remaining Logic Apps, we will use a different process:

  • Select the API you created in the previous step, BizTalk Alerts API.
  • And just above the All operations list, click + Add Operation.

BizTalk Alerts API

  • On the Frontend editor panel, add the following values and then select Save.
    • For the Display name type ports-notification
    • You can leave the Name as it is ports-notification
    • In the URL, choose POST and enter /ports/notification

frontend

  • On the operation that you created in the previous step, select Open Backend editor on the Backend panel

backend

  • On the Backend editor panel, modify the Target attribute to be Azure Logic App, and then on the Azure Resource, select Browse

Logic App to import

  • On the Select Logic App trigger to import panel, click Logic App and from the Select Logic App to import panel list, select the Logic App you want, in our case, POC-Monitor-BizTalk-Ports, and click Select.

Select Logic App trigger to import

  • Back to the Select Logic App trigger to import panel, select the Name of the trigger, manual, and click Save.

logic app API management

  • Back on the Backend editor panel, click Save.

Now we have two Logic App exposed in API Management with a proper naming convention. You can go ahead and try it again.

Finally, we need to do the same steps for the last Logic App, but in this case, on the Frontend editor panel, you need to add the following values

  • For the Display name type suspended-instances-notification
  • Leave the Name as it is suspended-instances-notification
  • In the URL, select POST and enter /suspended/instances/notification

BizTalk Alerts API

And on the Backend editor panel, we need to select our last Logic App: POC-Monitor-BizTalk-Suspended-Instances.

In the end, you will have a single API: BizTalk Alerts API composed of 3 operations with the following URLs:

  • POST host-instances-notification: https://<apim-name>.azure-api.net/biztalk-alert/host-instances/notification
  • POST ports-notification: https://<apim-name>.azure-api.net/biztalk-alert/ports/notification
  • POST suspended-instances-notification: https://<apim-name>.azure-api.net/biztalk-alert/suspended/instances/notification

Developer portal

With this approach, you will have a better way of exposing and combining your Logic Apps in different APIs according to that API’s scope. And above all, doing it following and implementing REST best practices.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.