Import Azure Logic App to Azure API Management programmatically
Published Aug 11 2021 02:03 AM 3,911 Views



In Azure API Management service, we can import Azure Logic App as a new API manually in Azure PortalAs referenced in this document about Import 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 instanceDevOps engineers wish to create a pipeline to automate the import process of the Azure Function app to APIM. 


You may notice that there isn’t any PowerShell command or Rest API available for us to use to automatic the import process at 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   
  • Testing the new API imported from Logic App 






1.Importing an Azure Logic App to Azure API Management manually in Azure Portal 


Follow the steps in this document: 


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 allI will need to export/download an OpenAPI definition file for my existing Logic App in APIMthen 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-AzApiManagementApi command. 


My example below 

Import-AzApiManagementApi -Context $ApiMgmtContext -SpecificationFormat "OpenApiJson"  -SpecificationPath "MYLOCALFILEPATH\haileylogicapp2.json" -Path $myPath 


After running the command, I can see my new Logic App (haileylogicapp2in APIM: 



4.Adding the authorization for the Logic APP in APIM with the Named Value  

As Azure Logic App needs an access key for HTTP requests, we will need to add access 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 Logic App(haileylogicapp2). 


  • Navigate to the Logic App Designers page, copy the Whole URL 



I got the whole URL for my new Logic App: 


  • 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. 



To add the named value, I run this New-AzApiManagementNamedValue cmdlet.  

Example below 

New-AzApiManagementNamedValue -Context $ApiMgmtContext -NamedValueId “haileylogicapp2-key”  -Name “haileylogicapp2-key”  -Value -WcznMep_1tZpqQrg8AdOmM8NfjbJB3UnvomN_pH8sc 




 5.Adding a backend service in APIM using New-AzApiManagementBackend 

 I need add the new Logic App into my APIM Backends. 

To achieve this, I can use the PowerShell command New-AzApiManagementBackend 


My example below: 

$apimContext = New-AzApiManagementContext -ResourceGroupName "APIMtest" -ServiceName "coolhailey" 

$backend = New-AzApiManagementBackend -Context  $apimContext -BackendId haileylogicapp2 -Url '’ -Protocol http -Title "haileylogicapp2"   -Description "my new Logic App 2" 


After run the above commands, I can see a new backend created, named with haileylogicapp2. 



6.Setting the backend service and request URL with the inbound policy 

I will need to set the logic app as the backend in the APIM inbound policy. At the same time, I need to append the authorization token to the request URL. 


To achieve that, I can use the set-backend-service and rewrite-uri: 

         <set-backend-service backend-id="haileylogicapp2"/> 

         <rewrite-uri template="/request/paths/invoke/?api-version=2016-10-01&amp;sp=/triggers/request/run&amp;sv=1.0&amp;sig={{haileylogicapp2-key}}" /> 


Then I ran the Set-AzApiManagementPolicy cmdlet. Example below: 



7.Testing my changes 

After all these steps above, I go back and verified my import. 

Send a test call and get a success 200: 






Version history
Last update:
‎Aug 11 2021 01:31 AM
Updated by: