In Azure API Management service, we can import Azure Logic App as a new APImanually in Azure Portal. As referenced in this document aboutImport a Logic App as an API
However, sometimes we wish to automate the import process of Azure Logic App to Azure API Management service (APIM). For instance, DevOps engineers wish to create apipeline to automate the import process of the AzureFunction app to APIM.
You may notice thatthere isn’t any PowerShell commandor Rest API available for us to use to automatic the import processat present. Usually, the command APIM supports is to import swagger file or WSDL file.
There is a certain workaround available now which enables us to achieve the automation process.Firstly, we need to create an open API definition file for the targeted Azure Logic app, and then we can import this swagger file into our APIM using PowerShell command Import-AzApiManagementApi.
In this blog, we will walk through the details on importing Logic App to APIM automatically, with the steps below:
Importing an Azure Logic App to Azure API Management manually
Generating an Open API definition file for the future imports
Importing the new Logic App to APIM by using the command Import-AzApiManagementApi
Adding the authorization for the Logic APP in APIM with the Named Value
Adding a backend service in APIM using New-AzApiManagementBackend
Setting the backend service and request URL with the inbound policy
After importing, I can see the Logic App in the API list, named with haileylogicapp
2.Generating an Open API definition file for future imports.
First of all, I will need to export/download an OpenAPIdefinition file for my existing Logic App in APIM, then I could modify the contents inside and save it for future automated importing processes.
Export the OpenAPI file of my Logic App(haileylogicapp)
In my case, I downloaded an OpenAPI v3 JSON.
The original JSON file I have downloaded:
Optional Modify the JSON file with my new Logic APP configuration if my new logic app has changed since the previous import.I should be able to find the information from my new logic App designer blade.
For example, I have made the following modification in Json file as highlighted in red.
3.Importing the new Logic App to APIM by using command Import-AzApiManagementApi
As I already have an OpenAPI file with my new Logic App configurations, now I am ready to import it. I will use Import-AzApiManagementApicommand.
After running the command, I can see my new Logic App (haileylogicapp2) in APIM:
4.Adding the authorization for the Logic APP in APIM with the Named Value
As Azure Logic App needs an access keyforHTTP requests, we will need to addaccess key information in the request URL from the APIM side. In order to do that, we need a named value to store the access key of my new LogicApp(haileylogicapp2).
Navigate to the Logic App Designers page, copy the Whole URL
Copy the value of the sig part (-WcznMep_1tZpqQrg8AdOmM8NfjbJB3UnvomN_pH8sc), and store it inside Named Value inside my APIM service. By doing so, next time if I regenerate the access keys, I could simply modify the named value without the need to change my API in APIM.