Calling a versioned API in API Management from Logic Apps

We use Azure API Management quite extensively at our clients, where we use this service whenever our services (APIs) go across application boundaries. Basically, API Management implements a facade in front of all our services. Any consumer, whether they are internal or external, uses this gateway to communicate with our services.

Image result for api management azure

On the other hand, we have Logic Apps, used to orchestrate our processes, by calling out to various services and creating a workflow depending on the outcomes. This includes services exposed through API Management as well, which is made easy by using the out of the box API Management action.

However, there is a small issue we can run into when taking this approach. By default, we use versioned APIs when working with API Management. Consequently ,this allows us to easily create a new version if needed at some point. However, the Logic Apps connector does not take this version into account, meaning we will get a 404 Resource not found error when calling our API in the Logic App.

The reason we receive this error, is because for this particular API we expect a query string with the API version, in our case v1. However, the connector does not automatically add this in our Logic App. Luckily it’s very easy to fix this issue, by adding the query string ourselves. Note that when using a header or path parameter you need to do this in another location, however the logic remains the same.

To implement the fix, open the Logic App in Code view and locate the API Management action. Here we add the following piece of JSON, which adds a query string parameter in the api-version field.

"queries": {
     "api-version": "v1"
},

Now when we use the action, the Logic App calls the correct endpoint, and our workflow executes as expected.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.