Welcome again to another Logic Apps Best Practices, Tips, and Tricks post. Today, we will discuss how to call from Logic App Standard an API exposed in API Management from a different subscription using the in-app API Management connector.
On May 08, 2023, Microsoft announced the availability of an APIM connector for Logic Apps Standard. This allows you to consume your APIs hosted in API Management from Logic Apps Standard workflows. Through the APIM connector, you get the same visual and low code experience as any other connector, thus providing a powerful way to extend the out-of-box connectors and consume your backend services and APIs. Bringing the support of the APIM connector in Logic Apps Standard also allows us to:
- Connect to your services and APIs hosted on-premises or in VNET.
- Because it is a built-in connector, it runs on the same computer as Logic Apps runtime, providing performance benefits at no extra cost.
But there is a catch! By design, and with that, I mean using the Logic App designer when we are creating the new connection:
We can only select an API Management instance that is present in the same subscription:
All those four API Management service instances you see in the picture are included in my personal subscription. The same subscription this Logic App Standard is deployed.
But this is the question: What if I want to call an API Management instance deployed in a different subscription inside my organization? Can I still use the API Management in-app connector, or must I use the HTTP connector?
In most of the solutions I see, developers choose to use the HTTP connector because it is simple. We can do everything with it. Maybe they are unaware that we can use the API Management in-app connector, or just because they don’t know how to use the API Management in-app connector to accomplish that! Yes, we can do everything with the HTTP connector, but that also brings other issues and constraints that we need to deal with later on for our Logic App Standard workflows to be in good shape.
Many people are unaware that with a simple tweak, we can use the API Management in-app connector to call an API exposed in an API Management service instance on a different subscription! To accomplish that, we need to:
- Access to our Logic App Standard connections under Workflows > Connections > JSON View
- Notice that in the picture I already have two connections pointing to two different subscriptions
- And manually add a new API Management connection with the following format:
"apiManagementOperation": {
"apiId": "/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.ApiManagement/service/<apimInstanceName>/apis/<apiName>",
"baseUrl": "<apiBaseUrl>",
"displayName": "<connectorName>",
"subscriptionKey": "@appsetting('apiManagementOperation_SubscriptionKey')"
}
Make sure you replace the following tags:
- <subscriptionId>: with the Subscription ID where the API Management service instance is deployed
- <resourceGroupName>: with the Resource Group name where the API Management service instance is deployed
- <apimInstanceName>: with the API Management service instance name
- <apiName>: with the API name you want to call
- <apiBaseUrl>: with the API base URL, you want to call
- and the <connectorName>: and of course, make sure you give a proper name to the connector.
Now that we have added a new API Management connection, we can select the API Management connector we want to use:
And by doing that, we can connector to different APIs that can be deployed in an APIM service instance deployed in the same subscription or in different subscriptions, as you can see below:
Kudo to Divya Swarnkar and Harold Campos for the help in setting up this functionality!
I hope you find this helpful! If you liked the content or found it helpful and want to help me write more content, you can buy (or help buy) my son a Star Wars Lego!