Receive and respond to inbound HTTPS requests in Azure Logic Apps

With Azure Logic Apps and the built-in Request trigger and Response action, you can create automated tasks and workflows that can receive inbound requests over HTTPS. To send outbound requests instead, use the built-in HTTP trigger or HTTP action.

For example, you can have your logic app:

  • Receive and respond to an HTTPS request for data in an on-premises database.

  • Trigger a workflow when an external webhook event happens.

  • Receive and respond to an HTTPS call from another logic app.

This article shows how to use the Request trigger and Response action so that your logic app can receive and respond to inbound calls.

For information about encryption, security, and authorization for inbound calls to your logic app, such as Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL), or Azure Active Directory Open Authentication (Azure AD OAuth), see Secure access and data - Access for inbound calls to request-based triggers.

Prerequisites

Add Request trigger

This built-in trigger creates a manually callable endpoint that can handle only inbound requests over HTTPS. When a caller sends a request to this endpoint, the Request trigger fires and runs the logic app. For more information about how to call this trigger, see Call, trigger, or nest workflows with HTTPS endpoints in Azure Logic Apps.

Your logic app keeps an inbound request open only for a limited time. Assuming that your logic app includes a Response action, if your logic app doesn't send a response back to the caller after this time passes, your logic app returns a 504 GATEWAY TIMEOUT status to the caller. If your logic app doesn't include a Response action,

your logic app immediately returns a 202 ACCEPTED status to the caller.

  1. Sign in to the Azure portal. Create a blank logic app.

  2. After Logic App Designer opens, in the search box, enter http request as your filter. From the triggers list, select the When an HTTP request is received trigger.

    Select Request trigger

    The Request trigger shows these properties:

    Request trigger

    Property name JSON property name Required Description
    HTTP POST URL {none} Yes The endpoint URL that's generated after you save the logic app and is used for calling your logic app
    Request Body JSON Schema schema No The JSON schema that describes the properties and values in the incoming request body
  3. In the Request Body JSON Schema box, optionally enter a JSON schema that describes the body in the incoming request, for example:

    Example JSON schema

    The designer uses this schema to generate tokens for the properties in the request. That way, your logic app can parse, consume, and pass along data from the request through the trigger into your workflow.

    Here is the sample schema:

    {
       "type": "object",
       "properties": {
          "account": {
             "type": "object",
             "properties": {
                "name": {
                   "type": "string"
                },
                "ID": {
                   "type": "string"
                },
                "address": {
                   "type": "object",
                   "properties": {
                      "number": {
                         "type": "string"
                      },
                      "street": {
                         "type": "string"
                      },
                      "city": {
                         "type": "string"
                      },
                      "state": {
                         "type": "string"
                      },
                      "country": {
                         "type": "string"
                      },
                      "postalCode": {
                         "type": "string"
                      }
                   }
                }
             }
          }
       }
    }
    

    When you enter a JSON schema, the designer shows a reminder to include the Content-Type header in your request and set that header value to application/json. For more information, see Handle content types.

    Reminder to include "Content-Type" header

    Here's what this header looks like in JSON format:

    {
       "Content-Type": "application/json"
    }
    

    To generate a JSON schema that's based on the expected payload (data), you can use a tool such as JSONSchema.net, or you can follow these steps:

    1. In the Request trigger, select Use sample payload to generate schema.

      Screenshot with "Use sample payload to generate schema" selected

    2. Enter the sample payload, and select Done.

      Enter sample payload to generate schema

      Here is the sample payload:

      {
         "account": {
            "name": "Contoso",
            "ID": "12345",
            "address": {
               "number": "1234",
               "street": "Anywhere Street",
               "city": "AnyTown",
               "state": "AnyState",
               "country": "USA",
               "postalCode": "11111"
            }
         }
      }
      
  4. To check that the inbound call has a request body that matches your specified schema, follow these steps:

    1. In the Request trigger's title bar, select the ellipses button (...).

    2. In the trigger's settings, turn on Schema Validation, and select Done.

      If the inbound call's request body doesn't match your schema, the trigger returns an HTTP 400 Bad Request error.

  5. To specify additional properties, open the Add new parameter list, and select the parameters that you want to add.

    Property name JSON property name Required Description
    Method method No The method that the incoming request must use to call the logic app
    Relative path relativePath No The relative path for the parameter that the logic app's endpoint URL can accept

    This example adds the Method property:

    Add Method parameter

    The Method property appears in the trigger so that you can select a method from the list.

    Select method

  6. Now, add another action as the next step in your workflow. Under the trigger, select Next step so that you can find the action that you want to add.

    For example, you can respond to the request by adding a Response action, which you can use to return a customized response and is described later in this topic.

    Your logic app keeps the incoming request open only for a limited time. Assuming that your logic app workflow includes a Response action, if the logic app doesn't return a response after this time passes, your logic app returns a 504 GATEWAY TIMEOUT to the caller. Otherwise, if your logic app doesn't include a Response action, your logic app immediately returns a 202 ACCEPTED response to the caller.

  7. When you're done, save your logic app. On the designer toolbar, select Save.

    This step generates the URL to use for sending the request that triggers the logic app. To copy this URL, select the copy icon next to the URL.

    URL to use triggering your logic app

    Note

    If you want to include the hash or pound symbol (#) in the URI when making a call to the Request trigger, use this encoded version instead: %25%23

  8. To trigger your logic app, send an HTTP POST to the generated URL.

    For example, you can use a tool such as Postman to send the HTTP POST. For more information about the trigger's underlying JSON definition and how to call this trigger, see these topics, Request trigger type and Call, trigger, or nest workflows with HTTP endpoints in Azure Logic Apps.

Trigger outputs

Here's more information about the outputs from the Request trigger:

JSON property name Data type Description
headers Object A JSON object that describes the headers from the request
body Object A JSON object that describes the body content from the request

Add a Response action

When you use the Request trigger to handle inbound requests, you can model the response and send the payload results back to the caller by using the built-in Response action. You can use the Response action only with the Request trigger. This combination with the Request trigger and Response action creates the request-response pattern. Except for inside Foreach loops and Until loops, and parallel branches, you can add the Response action anywhere in your workflow.

Important

If a Response action includes these headers, Logic Apps removes these headers from the generated response message without showing any warning or error:

  • Allow
  • Content-* with these exceptions: Content-Disposition, Content-Encoding, and Content-Type
  • Cookie
  • Expires
  • Last-Modified
  • Set-Cookie
  • Transfer-Encoding

Although Logic Apps won't stop you from saving logic apps that have a Response action with these headers, Logic Apps ignores these headers.

  1. In the Logic App Designer, under the step where you want to add a Response action, select New step.

    For example, using the Request trigger from earlier:

    Add new step

    To add an action between steps, move your pointer over the arrow between those steps. Select the plus sign (+) that appears, and then select Add an action.

  2. Under Choose an action, in the search box, enter response as your filter, and select the Response action.

    Select the Response action

    The Request trigger is collapsed in this example for simplicity.

  3. Add any values that are required for the response message.

    In some fields, clicking inside their boxes opens the dynamic content list. You can then select tokens that represent available outputs from previous steps in the workflow. Properties from the schema specified in the earlier example now appear in the dynamic content list.

    For example, for the Headers box, include Content-Type as the key name, and set the key value to application/json as mentioned earlier in this topic. For the Body box, you can select the trigger body output from the dynamic content list.

    Response action details

    To view the headers in JSON format, select Switch to text view.

    Headers - Switch to text view

    Here is more information about the properties that you can set in the Response action.

    Property name JSON property name Required Description
    Status Code statusCode Yes The status code to return in the response
    Headers headers No A JSON object that describes one or more headers to include in the response
    Body body No The response body
  4. To specify additional properties, such as a JSON schema for the response body, open the Add new parameter list, and select the parameters that you want to add.

  5. When you're done, save your logic app. On the designer toolbar, select Save.

Next steps