|
1 | 1 | ---
|
2 |
| -title: Use request and response actions | Microsoft Docs |
3 |
| -description: Overview of the request and response trigger and action in an Azure logic app |
4 |
| -services: '' |
5 |
| -documentationcenter: '' |
6 |
| -author: jeffhollan |
7 |
| -manager: erikre |
8 |
| -editor: '' |
9 |
| -tags: connectors |
10 |
| - |
11 |
| -ms.assetid: 566924a4-0988-4d86-9ecd-ad22507858c0 |
| 2 | +title: Respond to HTTP or HTTPS requests - Azure Logic Apps |
| 3 | +description: Respond to events in real time over HTTP or HTTPS by using Azure Logic Apps |
| 4 | +services: logic-apps |
12 | 5 | ms.service: logic-apps
|
13 |
| -ms.devlang: na |
| 6 | +ms.suite: integration |
| 7 | +author: ecfan |
| 8 | +ms.author: estfan |
| 9 | +ms.reviewers: klam, LADocs |
| 10 | +manager: carmonm |
| 11 | +ms.assetid: 566924a4-0988-4d86-9ecd-ad22507858c0 |
14 | 12 | ms.topic: article
|
15 |
| -ms.tgt_pltfrm: na |
16 |
| -ms.workload: na |
17 |
| -ms.date: 07/18/2016 |
18 |
| -ms.author: jehollan |
19 |
| - |
| 13 | +ms.date: 09/06/2019 |
| 14 | +tags: connectors |
20 | 15 | ---
|
21 |
| -# Get started with the request and response components |
22 |
| -With the request and response components in a logic app, you can respond in real time to events. |
23 | 16 |
|
24 |
| -For example, you can: |
| 17 | +# Respond to HTTP or HTTPS requests by using Azure Logic Apps |
| 18 | + |
| 19 | +With [Azure Logic Apps](../logic-apps/logic-apps-overview.md) and the built-in Request trigger or Response action, you can create automated tasks and workflows that react and respond in real time to events that are sent over HTTP or HTTPS. For example, you can have your logic app: |
| 20 | + |
| 21 | +* Respond to an HTTP request for data in an on-premises database. |
| 22 | +* Trigger a workflow when an external webhook event happens. |
| 23 | +* Call a logic app from within another logic app. |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +* An Azure subscription. If you don't have a subscription, you can [sign up for a free Azure account](https://azure.microsoft.com/free/). |
| 28 | + |
| 29 | +* Basic knowledge about [logic apps](../logic-apps/logic-apps-overview.md). If you're new to logic apps, learn [how to create your first logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md). |
| 30 | + |
| 31 | +<a name="add-request"></a> |
| 32 | + |
| 33 | +## Add the Request trigger |
| 34 | + |
| 35 | +This built-in trigger creates an endpoint that waits for and receives an incoming request over HTTP or HTTPS. When this event happens, the trigger fires and runs the logic app. |
| 36 | + |
| 37 | +1. Sign in to the [Azure portal](https://portal.azure.com). Create a blank logic app. |
| 38 | + |
| 39 | +1. 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, which is the first step in your logic app workflow. |
| 40 | + |
| 41 | +  |
| 42 | + |
| 43 | +1. For the **Request Body JSON Schema** box, you can optionally enter a JSON schema that describes the HTTP request body that's expected in the incoming request, for example: |
| 44 | + |
| 45 | +  |
| 46 | + |
| 47 | + 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. |
| 48 | + |
| 49 | + Here is the sample schema: |
25 | 50 |
|
26 |
| -* Respond to an HTTP request with data from an on-premises database through a logic app. |
27 |
| -* Trigger a logic app from an external webhook event. |
28 |
| -* Call a logic app with a request and response action from within another logic app. |
| 51 | + ```json |
| 52 | + { |
| 53 | + "type": "object", |
| 54 | + "properties": { |
| 55 | + "account": { |
| 56 | + "type": "object", |
| 57 | + "properties": { |
| 58 | + "name": { |
| 59 | + "type": "string" |
| 60 | + }, |
| 61 | + "ID": { |
| 62 | + "type": "string" |
| 63 | + }, |
| 64 | + "address": { |
| 65 | + "type": "object", |
| 66 | + "properties": { |
| 67 | + "number": { |
| 68 | + "type": "string" |
| 69 | + }, |
| 70 | + "street": { |
| 71 | + "type": "string" |
| 72 | + }, |
| 73 | + "city": { |
| 74 | + "type": "string" |
| 75 | + }, |
| 76 | + "state": { |
| 77 | + "type": "string" |
| 78 | + }, |
| 79 | + "country": { |
| 80 | + "type": "string" |
| 81 | + }, |
| 82 | + "postalCode": { |
| 83 | + "type": "string" |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + ``` |
29 | 92 |
|
30 |
| -To get started using the request and response actions in a logic app, see [Create a logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md). |
| 93 | + 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](../logic-apps/logic-apps-content-type.md). |
31 | 94 |
|
32 |
| -## Use the HTTP Request trigger |
33 |
| -A trigger is an event that can be used to start the workflow that is defined in a logic app. |
34 |
| -[Learn more about triggers](../connectors/apis-list.md). |
| 95 | +  |
35 | 96 |
|
36 |
| -Here's an example sequence of how to set up an HTTP request in the Logic App Designer. |
| 97 | + Here's what this header looks like in JSON format: |
37 | 98 |
|
38 |
| -1. Add the trigger **Request - When an HTTP request is received** in your logic app. You can optionally provide a JSON schema (by using a tool like [JSONSchema.net](https://jsonschema.net)) for the request body. This allows the designer to generate tokens for properties in the HTTP request. |
39 |
| -2. Add another action so that you can save the logic app. |
40 |
| -3. After saving the logic app, you can get the HTTP request URL from the request card. |
41 |
| -4. An HTTP POST (you can use a tool like [Postman](https://www.getpostman.com/)) to the URL triggers the logic app. |
| 99 | + ```json |
| 100 | + { |
| 101 | + "Content-Type": "application/json" |
| 102 | + } |
| 103 | + ``` |
42 | 104 |
|
43 |
| -> [!NOTE] |
44 |
| -> If you don't define a response action, a `202 ACCEPTED` response is immediately returned to the caller. You can use the response action to customize a response. |
45 |
| -> |
46 |
| -> |
| 105 | + To generate a JSON schema that's based on the expected payload (data), you can use a tool such as [JSONSchema.net](https://jsonschema.net), or you can follow these steps: |
47 | 106 |
|
48 |
| - |
| 107 | + 1. In the Request trigger, select **Use sample payload to generate schema**. |
49 | 108 |
|
50 |
| -## Use the HTTP Response action |
51 |
| -The HTTP Response action is only valid when you use it in a workflow that is triggered by an HTTP request. If you don't define a response action, a `202 ACCEPTED` response is immediately returned to the caller. You can add a response action at any step within the workflow. The logic app only keeps the incoming request open for one minute for a response. After one minute, if no response was sent from the workflow (and a response action exists in the definition), a `504 GATEWAY TIMEOUT` is returned to the caller. |
| 109 | +  |
52 | 110 |
|
53 |
| -Here's how to add an HTTP Response action: |
| 111 | + 1. Enter the sample payload, and select **Done**. |
54 | 112 |
|
55 |
| -1. Select the **New Step** button. |
56 |
| -2. Choose **Add an action**. |
57 |
| -3. In the action search box, type **response** to list the Response action. |
58 |
| - |
59 |
| -  |
60 |
| -4. Add in any parameters that are required for the HTTP response message. |
61 |
| - |
62 |
| -  |
63 |
| -5. Click the upper-left corner of the toolbar to save, and your logic app will both save and publish (activate). |
| 113 | +  |
64 | 114 |
|
65 |
| -## Request trigger |
66 |
| -Here are the details for the trigger that this connector supports. There is a single request trigger. |
| 115 | + Here is the sample payload: |
67 | 116 |
|
68 |
| -| Trigger | Description | |
69 |
| -| --- | --- | |
70 |
| -| Request |Occurs when an HTTP request is received | |
| 117 | + ```json |
| 118 | + { |
| 119 | + "account": { |
| 120 | + "name": "Contoso", |
| 121 | + "ID": "12345", |
| 122 | + "address": { |
| 123 | + "number": "1234", |
| 124 | + "street": "Anywhere Street", |
| 125 | + "city": "AnyTown", |
| 126 | + "state": "AnyState", |
| 127 | + "country": "USA", |
| 128 | + "postalCode": "11111" |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + ``` |
71 | 133 |
|
72 |
| -## Response action |
73 |
| -Here are the details for the action that this connector supports. There is a single response action that can only be used when it is accompanied by a request trigger. |
| 134 | +1. To specify additional properties, such as the expected method used for the request or a relative path, open the **Add new parameter** list, and select the parameters that you want to add. |
74 | 135 |
|
75 |
| -| Action | Description | |
76 |
| -| --- | --- | |
77 |
| -| Response |Returns a response to the correlated HTTP request | |
| 136 | + This example adds the **Method** parameter: |
78 | 137 |
|
79 |
| -### Trigger and action details |
80 |
| -The following tables describe the input fields for the trigger and action, and the corresponding output details. |
| 138 | +  |
81 | 139 |
|
82 |
| -#### Request trigger |
83 |
| -The following is an input field for the trigger from an incoming HTTP request. |
| 140 | + Now the **Method** parameter appears in the trigger so that you can select a method from the list. |
84 | 141 |
|
85 |
| -| Display name | Property name | Description | |
86 |
| -| --- | --- | --- | |
87 |
| -| JSON Schema |schema |The JSON schema of the HTTP request body | |
| 142 | +  |
88 | 143 |
|
89 |
| -<br> |
| 144 | +1. 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. |
| 145 | + |
| 146 | + For example, you can respond to the request by [adding a Response action](#add-response), which is described later in this topic. |
| 147 | + |
| 148 | + > [!NOTE] |
| 149 | + > If you don't include and define a Response action in your logic app workflow, |
| 150 | + > your logic app immediately returns a `202 ACCEPTED` response to the caller. |
| 151 | + > You can use the Response action to customize a response. |
| 152 | + |
| 153 | +1. When you're done, save your logic app. On the designer toolbar, select **Save**. |
| 154 | + |
| 155 | + 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. |
| 156 | + |
| 157 | +  |
90 | 158 |
|
91 |
| -**Output details** |
| 159 | +1. To trigger your logic app, send an HTTP POST to the generated URL. For example, you can use a tool such as [Postman](https://www.getpostman.com/). |
92 | 160 |
|
93 |
| -The following are output details for the request. |
| 161 | +### Trigger outputs |
| 162 | + |
| 163 | +Here's more information about the outputs from the Request trigger: |
94 | 164 |
|
95 | 165 | | Property name | Data type | Description |
|
96 |
| -| --- | --- | --- | |
97 |
| -| Headers |object |Request headers | |
98 |
| -| Body |object |Request object | |
| 166 | +|---------------|-----------|-------------| |
| 167 | +| `headers` | Object | A JSON object that describes the headers from the request | |
| 168 | +| `body` | Object | A JSON object that describes the body content from the request | |
| 169 | +|||| |
| 170 | + |
| 171 | +<a name="add-response"></a> |
| 172 | + |
| 173 | +## Add a Response action |
| 174 | + |
| 175 | +You can use the Response action to customize a response but only in a logic app workflow that's triggered by an HTTP request. You can add the Response action at any point in your workflow. |
| 176 | + |
| 177 | +Your logic app keeps the incoming request open only for one minute. 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. However, if your logic app doesn't include a Response action, your logic app immediately returns a `202 ACCEPTED` response to the caller. |
| 178 | + |
| 179 | +1. In the Logic App Designer, under the step where you want to add a Response action, select **New step**. |
| 180 | + |
| 181 | + For example, using the Request trigger from earlier: |
| 182 | + |
| 183 | +  |
| 184 | + |
| 185 | + 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**. |
| 186 | + |
| 187 | +1. Under **Choose an action**, in the search box, enter "response" as your filter, and select the **Response** action. |
| 188 | + |
| 189 | +  |
| 190 | + |
| 191 | + The Request trigger is collapsed in this example for simplicity. |
| 192 | + |
| 193 | +1. Add any values that are required for the response message. |
| 194 | + |
| 195 | + 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. |
| 196 | + |
| 197 | + For example, in the **Headers** field, include `Content-Type` as the key name and set the key value to `application/json`, as mentioned earlier in this topic. For the **Body** field, you can select the trigger body from the dynamic content list. |
| 198 | + |
| 199 | +  |
| 200 | + |
| 201 | + To view the headers in JSON format, select **Switch to text view**. |
| 202 | + |
| 203 | +  |
| 204 | + |
| 205 | + Here is more information about the properties that you can set in the Response action. |
| 206 | + |
| 207 | + | Display name | Property name | Required | Description | |
| 208 | + |--------------|---------------|----------|-------------| |
| 209 | + | Status Code | `statusCode` | Yes | The HTTP status code to return | |
| 210 | + | Headers | `headers` | No | A JSON object that describes any response headers to include. | |
| 211 | + | Body | `body` | No | The response body | |
| 212 | + ||||| |
99 | 213 |
|
100 |
| -#### Response action |
101 |
| -The following are input fields for the HTTP Response action. A * means that it is a required field. |
| 214 | +1. To specify additional properties, such as a JSON schema for the response, open the **Add new parameter** list, and select the parameters that you want to add. |
102 | 215 |
|
103 |
| -| Display name | Property name | Description | |
104 |
| -| --- | --- | --- | |
105 |
| -| Status Code* |statusCode |The HTTP status code | |
106 |
| -| Headers |headers |A JSON object of any response headers to include | |
107 |
| -| Body |body |The response body | |
| 216 | +1. When you're done, save your logic app. On the designer toolbar, select **Save**. |
108 | 217 |
|
109 | 218 | ## Next steps
|
110 |
| -Now, try out the platform and [create a logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md). You can explore the other available connectors in logic apps by looking at our [APIs list](apis-list.md). |
111 | 219 |
|
| 220 | +* [Connectors for Logic Apps](../connectors/apis-list.md) |
0 commit comments