Calling Azure Function Proxy with Open API definition from Logic App

I got a task from a project recently to make a call to an API from Logic Apps, and I thought that this was going to be an easy thing to do and there will be no challenges. And it was kind of easy, but I still had to learn some things along the way until the completion of the task.

Azure Function Proxy

First of all, to make the call to the API, we decided to use an Azure Function Proxy, to hide the final endpoint from Logic Apps and also to try to limit the outbound IP address to only a few instead of a full region like it would be calling directly from Logic Apps.

So, we created an Azure Function and created the proxy as below:

At this point, we were ready to go and consume this proxy from Logic Apps, by using the Azure Function connector, but for that to happen we needed to make a few changes in the configuration of the Azure Function.

CORS

First, we needed to enable CORS to enable the Logic Apps editor to be able to get the Open API definition (we will get there soon).

Without enabling CORS, we got the following error from the Logic Apps designer:

We have two options here depending on how much we want to restrict callers. We can add an asterisk to the allowed origins in the CORS configuration or we can restrict to a few addresses by using https://ema.hosting.portal.azure.net (which is the URL where requests come from when using the Logic Apps designer). I choose the latter and added this address to the list that was already there.

     

API Definition

Once we have the CORS sorted out, now it’s time to check why the Proxy function is not showing up when using the connector as you can see below.

So, to make this happen we are going to configure the API definition of this Azure Function. To do so, go to the Platform features of the Azure Function and in the API section click on API definition. A blade as the image below will open up.

Click on the button “Generate API definition template” and it will get the Functions and Proxies defined in your Azure Function. But it will not specify data types being exchanged and this is where you can customize the YAML to represent them.

So in this example, let’s say I want to receive the following JSON:

To do so, we need to customize the YAML to the following. Please note that Azure Functions by now supports the Open API specification version 2: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

Calling in Logic Apps

Now that the Open API definition is configured in the Azure Function we can go back to Logic Apps and try to call it by using the Azure Function connector.

Summary

So, with the help of an Open API definition, we have a very seamless behavior of the Azure Function for both Functions and Proxies when using them in Logic Apps.

Add a Comment

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