none
Get a swagger file for an Azure logic app RRS feed

  • Question

  • I want to deploy my API resources using templates, I have hit an issue with using an ARM template to deploy or import an API, LogicApp, into API management.  When you do this via the portal it works fine and pulls in all the operations available (clearly it gets the swagger file from somewhere behind the scenes).

    I found the below resource which allowed me to get the swagger file for my Logic app.  I could then get a copy of this config and reference this as a local file or save this to a public URL which would allow me to deploy the API to APIM and it pull in the API config using an ARM template.

    https://docs.microsoft.com/en-us/rest/api/logic/workflows/listswagger

    I have other open APIs which I can deploy in ARM as I can get the swagger config from a public URI.  What I want to be able to do is import the Logic App API via ARM template or PowerShell and for it to be able to pull in this swagger file from the Logic app at deployment time. Is there a way to do this?

    Thanks in Advance.



    Thursday, October 17, 2019 5:20 PM

All replies

  • I believe there is no way to achieve this using just ARM Templates. But with PowerShell and ARM Templates, it should be possible.

    Unfortunately, there is no built-in powershell cmdlet for fetching the swagger spec for a logic app. Please feel free to open a feature request on UserVoice for it.\

    So, you would have to get the swagger spec for your Logic App using Invoke-RestMethod. To make this call, you have to get the access token first which is a bit hacky but something like this does work (discussed in this issue). This will be simplified once Invoke-AzRestMethod is implemented.

    $currentAzureContext = Get-AzContext
    $azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile;
    $profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile);
    $accessToken = $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken;

    Once you have this content, you can then run your deployment template passing in the content as a parameter. Do note that you have to set the format property to swagger-json.


    Monday, October 21, 2019 5:20 AM
    Moderator
  • Thank you, I have just tested this method and it works well.  This has given me a good workaround where I can deploy my Logic app API via PowerShell with this Swagger file or reference the swagger file in an ARM template.  I look forward to seeing more about the Invoke-AzRestMethod cmdlet!
    Monday, October 21, 2019 12:56 PM