Rediger

Del via


Call REST API endpoints from workflows in Azure Logic Apps by using HTTP Swagger

Applies to: Azure Logic Apps (Consumption + Standard)

To call a REST API from your workflow in Azure Logic Apps without manually building a request, add the native, built-in HTTP + Swagger trigger or action to your workflow. These operations call any REST API endpoint by using a Swagger file to discover callable operations and get structured inputs and outputs.

The HTTP + Swagger trigger and action work the same as the HTTP trigger and action, but they provide a better experience in the workflow designer by exposing the API structure and outputs described by the Swagger file.

This article shows how to add and use the HTTP + Swagger trigger and action in your workflow.

Limitations

The HTTP + Swagger built-in operations support only OpenAPI 2.0, not OpenAPI 3.0.

Prerequisites

  • An Azure account and subscription. Get a free Azure account.

  • The URL for the Swagger file that describes the target REST API endpoint to call.

    Typically, the REST endpoint needs to meet the following criteria for the trigger or action to work:

  • A Consumption or Standard logic app workflow where you want to call the REST API endpoint.

    To start your workflow with the HTTP + Swagger trigger, create a logic app resource that has a blank workflow. To use the HTTP + Swagger action, start your workflow with any trigger that works best for your business scenario.

Add an HTTP + Swagger trigger

This trigger sends an HTTP request to the URL for a Swagger file that describes a REST API. The trigger returns a response that contains the Swagger file content to the workflow.

To implement a polling trigger, follow the polling trigger pattern.

  1. In the Azure portal, open your logic app resource.

  2. In the designer, open your blank workflow.

  3. Based on whether your workflow is Consumption or Standard, follow the general steps to add the HTTP trigger named HTTP + Swagger.

  4. In the Swagger endpoint box, enter the URL for the Swagger file, and select Add action.

    The following example shows an example Swagger URL format. Your URL might use a different format.

    Screenshot that shows the Azure portal, workflow designer, and HTTP + Swagger trigger pane. An example URL is entered for the Swagger endpoint parameter.

    The trigger information pane shows the operations in the Swagger file.

  5. Select the operation you want.

  6. For the selected operation, enter the parameter values to use in the REST API call.

    Parameters vary based on the selected operation.

  7. If the trigger runs on a schedule, set up the recurrence to specify when the trigger calls the REST API.

  8. If other parameters exist, open the Advanced parameters list, and select the parameters you want.

    For more information about authentication, see Add authentication to outbound calls.

  9. Continue building the workflow with actions to run when the trigger fires.

  10. When you finish, save your workflow. On the designer toolbar, select Save.

Add an HTTP + Swagger action

This action sends an HTTP request to the URL for a Swagger file that describes a REST API. The action returns a response that contains the Swagger file content to the workflow.

  1. In the Azure portal, open your logic app resource.

  2. In the designer, open your blank workflow.

  3. Based on whether your workflow is Consumption or Standard, follow the general steps to add the HTTP action named HTTP + Swagger.

  4. In the Swagger endpoint box, enter the URL for the Swagger file, and select Add action.

    The following example shows an example Swagger URL format. Your URL might use a different format.

    Screenshot that shows the Azure portal, workflow designer, and HTTP + Swagger action pane. An example URL is entered for the Swagger endpoint parameter.

    The action information pane shows the operations in the Swagger file.

  5. Select the operation you want.

  6. For the selected operation, enter the parameter values to use in the REST API call.

    Parameters vary based on the selected operation.

  7. If other parameters exist, open the Advanced parameters list, and select the parameters you want.

    For more information about authentication, see Add authentication to outbound calls.

  8. Continue building the workflow with actions to run when the trigger fires.

  9. When you finish, save your workflow. On the designer toolbar, select Save.

Outputs from HTTP + Swagger operations

This section provides more information about the outputs from the HTTP + Swagger trigger and action. The HTTP + Swagger operation returns the following information:

Property name Type Description
headers Object The headers from the request.
body Object The object with the body content from the request.
status code Integer The status code from the request.
Status code Description
200 OK
202 Accepted
400 Bad request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal server error. Unknown error occurred.

Host the Swagger in Azure Storage

You can still reference a Swagger file that's not hosted or that doesn't meet the security and cross-origin requirements. Upload the Swagger file to a blob container in an Azure storage account and turn on CORS on the storage account.

To create, set up, and store Swagger files in Azure Storage, follow these steps:

  1. In the Azure portal, create an Azure storage account.

  2. Turn on CORS for the blob by following these steps:

    1. On the storage account sidebar, under Settings, select CORS.

    2. On the Blob service tab, enter the following values, and select Save.

      Parameter Value
      Allowed origins *
      Allowed methods GET, HEAD, PUT
      Allowed headers *
      Exposed headers *
      Max age in seconds 200

    This example uses the Azure portal, but you can use a tool like Azure Storage Explorer to configure this setting. To automate configuration, see the sample PowerShell script.

  3. Create a blob container and follow these steps:

    1. On the container sidebar, select Overview.

    2. On the Overview page, select Change access level.

    3. From the Public access level list, select Blob (anonymous read access for blobs only), and then select OK.

  4. In the Azure portal or Azure Storage Explorer, upload the Swagger file to the blob container.

  5. To reference the file in the blob container, from Azure Storage Explorer, get the HTTPS URL that uses the following case-sensitive format:

    https://<storage-account-name>.blob.core.windows.net/<blob-container-name>/<complete-swagger-file-name>?<query-parameters>