你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本参考文档介绍用于在逻辑应用的基础工作流定义(由工作流定义语言描述和验证)中标识触发器和操作的通用类型。 To find specific connector triggers and actions that you can use in your logic apps, see the list under the Connectors overview.
Triggers overview
每个工作流包含一个触发器,该触发器定义了可以实例化并启动该工作流的调用。 以下为常规触发器类型:
A polling trigger, which checks a service's endpoint at regular intervals
A push trigger, which creates a subscription to an endpoint and provides a callback URL so the endpoint can notify the trigger when the specified event happens or data is available. 然后触发器等待终结点的响应,接着才触发。
触发器都具有以下顶级元素,但有一些是可选元素:
"<trigger-name>": {
"type": "<trigger-type>",
"inputs": { "<trigger-inputs>" },
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>
},
"conditions": [ "<array-with-conditions>" ],
"runtimeConfiguration": { "<runtime-config-options>" },
"splitOn": "<splitOn-expression>",
"operationOptions": "<operation-option>"
},
Required
Value | 类型 | Description |
---|---|---|
< trigger-name> | String | 触发器的名称 |
< trigger-type> | String | 触发器类型,例如“Http”或“ApiConnection” |
< trigger-inputs> | JSON Object | 定义触发器行为的输入 |
< time-unit> | String | 用于描述触发器触发频率的时间单位:“秒”、“分钟”、“小时”、“天”、“周”、“月” |
< number-of-time-units> | Integer | 指定触发器触发频率的值,即触发器再次触发之前需等待的时间单位数 下面是最小和最大间隔: - 月:1-16 个月 - 天:1-500 天 - 小时:1-12,000 小时 - 分钟:1-72,000 分钟 - 秒:1-9,999,999 秒 例如,如果间隔为 6,频率为“月”,则重复周期为每 6 个月。 |
Optional
Value | 类型 | Description |
---|---|---|
< array-with-conditions> | Array | An array that contains one or more conditions that determine whether to run the workflow. 仅适用于触发器。 |
< runtime-config-options> | JSON Object | 通过设置 runtimeConfiguration 属性可更改触发器运行时行为。 有关详细信息,请参阅运行时配置设置。 |
< splitOn-expression> | String | 对于返回数组的触发器,可指定一个将数组项拆分或解除批处理到多个工作流实例进行处理的表达式。 |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
触发器类型列表
每个触发器类型用于定义其行为的接口和输入不同。
Built-in triggers
Trigger type | Description |
---|---|
HTTP | Checks or polls any endpoint. 此终结点必须使用 202 异步模式或返回一个数组,以符合特定的触发约定。 |
HTTPWebhook | 为逻辑应用创建一个可调用的终结点,但调用指定的 URL 来注册或注销。 |
Recurrence | 根据定义的计划执行。 可以设置在将来某个日期和时间执行此触发器。 根据频率,还可指定运行工作流的次数和天数。 |
Request | 为逻辑应用创建一个可调用的终结点,此类触发器也称为“手动”触发器。 相关示例请参阅使用 HTTP 终结点调用、触发或嵌套工作流。 |
托管的 API 触发器
Trigger type | Description |
---|---|
ApiConnection | Checks or polls an endpoint by using Microsoft-managed APIs or "connectors". |
ApiConnectionWebhook | 通过调用 Microsoft 托管 API 或“连接器”为逻辑应用工作流创建可调用的终结点以进行订阅和取消订阅。 |
触发器 - 详细参考
APIConnection trigger
This trigger checks or polls an endpoint by using Microsoft-managed APIs or "connectors" so the parameters for this trigger can differ based on the endpoint. 此触发器定义中的许多部分是可选的。 触发器的行为取决于是否包含部分。
"<APIConnection_trigger_name>": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['<connection-name>']['connectionId']"
}
},
"method": "<method-type>",
"path": "/<api-operation>",
"retryPolicy": { "<retry-behavior>" },
"queries": { "<query-parameters>" }
},
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>
},
"runtimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-runs-queue>
}
},
"splitOn": "<splitOn-expression>",
"operationOptions": "<operation-option>"
}
Required
Property | Value | 类型 | Description |
---|---|---|---|
None | < APIConnection_trigger_name> | String | 触发器的名称 |
host.connection.name | < connection-name> | String | 工作流使用的托管 API 连接的名称 |
method | < method-type> | String | The HTTP method for communicating with the managed API: GET, PUT, POST, PATCH, DELETE |
path | < api-operation> | String | 要调用的 API 操作 |
recurrence.frequency | < time-unit> | String | The unit of time that describes how often the trigger fires: Second, Minute, Hour, Day, Week, Month |
recurrence.interval | < number-of-time-units> | Integer | 指定触发器触发频率的值,即触发器再次触发之前需等待的时间单位数 下面是最小和最大间隔: - 月:1-16 个月 - 天:1-500 天 - 小时:1-12,000 小时 - 分钟:1-72,000 分钟 - 秒:1-9,999,999 秒 For example, if the interval is 6, and the frequency is Month, the recurrence is every 6 months. |
Optional
Property | Value | 类型 | Description |
---|---|---|---|
retryPolicy | < retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
queries | < query-parameters> | JSON Object | 要包括在 API 调用中的任何查询参数。 例如,"queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
runtimeConfiguration.concurrency.runs | < max-runs> | Integer | By default, workflow instances run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
runtimeConfiguration.maximumWaitingRuns | < max-runs-queue> | Integer | If your workflow is already running the maximum number of instances, any new runs are put in this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 To change the maximum number of instances, specify a value for the runtimeConfiguration.concurrency.runs property. Note: If you set the |
splitOn | < splitOn-expression> | String | 对于返回数组的触发器,此表达式引用要使用的数组,从而可为每个数组项创建和运行一个工作流实例,而不是使用“for each”循环。 例如,此表达式表示触发器正文内容中返回的数组中的某一项: @triggerbody()?['value'] |
operationOptions | < operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Outputs
Element | 类型 | Description |
---|---|---|
headers | JSON Object | 响应的标头 |
body | JSON Object | 响应的正文 |
status code | Integer | 响应中的状态代码 |
Example
此触发器定义每天都会在工作或学校帐户的收件箱中检查电子邮件:
"When_a_new_email_arrives": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "get",
"path": "/Mail/OnNewEmail",
"queries": {
"fetchOnlyWithAttachment": false,
"folderPath": "Inbox",
"importance": "Any",
"includeAttachments": false
}
},
"recurrence": {
"frequency": "Day",
"interval": 1
}
}
ApiConnectionWebhook trigger
This trigger sends a subscription request to an endpoint by using a Microsoft-managed API, provides a callback URL to where the endpoint can send a response, and waits for the endpoint to respond. For more information, see Endpoint subscriptions.
"<ApiConnectionWebhook_trigger_name>": {
"type": "ApiConnectionWebhook",
"inputs": {
"body": {
"NotificationUrl": "@{listCallbackUrl()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['<connection-name>']['connectionId']"
}
},
"retryPolicy": { "<retry-behavior>" },
"queries": "<query-parameters>"
},
"runTimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-run-queue>
}
},
"splitOn": "<splitOn-expression>",
"operationOptions": "<operation-option>"
}
Required
Value | 类型 | Description |
---|---|---|
< connection-name> | String | 工作流使用的托管 API 连接的名称 |
< body-content> | JSON Object | 要作为有效负载发送到托管 API 的任何消息内容 |
Optional
Value | 类型 | Description |
---|---|---|
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
< query-parameters> | JSON Object | 要包括在 API 调用中的任何查询参数 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
< max-runs> | Integer | By default, workflow instances run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
< max-runs-queue> | Integer | When your workflow is already running the maximum number of instances, which you can change based on the runtimeConfiguration.concurrency.runs property, any new runs are put into this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 |
< splitOn-expression> | String | 对于返回数组的触发器,此表达式引用要使用的数组,从而可为每个数组项创建和运行一个工作流实例,而不是使用“for each”循环。 例如,此表达式表示触发器正文内容中返回的数组中的某一项: @triggerbody()?['value'] |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Example
此触发器定义订阅 Office 365 Outlook API,提供 API 终结点的回叫 URL,并在新邮件到达时等待终结点响应。
"When_a_new_email_arrives_(webhook)": {
"type": "ApiConnectionWebhook",
"inputs": {
"body": {
"NotificationUrl": "@{listCallbackUrl()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"path": "/MailSubscription/$subscriptions",
"queries": {
"folderPath": "Inbox",
"hasAttachment": "Any",
"importance": "Any"
}
},
"splitOn": "@triggerBody()?['value']"
}
HTTP trigger
此触发器基于指定的定期计划向指定的 HTTP 或 HTTPS 终结点发送请求。 然后,此触发器检查响应以确定工作流是否运行。 有关详细信息,请参阅从 Azure 逻辑应用通过 HTTP 或 HTTPS 调用服务终结点。
"HTTP": {
"type": "Http",
"inputs": {
"method": "<method-type>",
"uri": "<HTTP-or-HTTPS-endpoint-URL>",
"headers": { "<header-content>" },
"queries": "<query-parameters>",
"body": "<body-content>",
"authentication": { "<authentication-type-and-property-values>" },
"retryPolicy": {
"type": "<retry-behavior>"
}
},
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>
},
"runtimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-runs-queue>
}
},
"operationOptions": "<operation-option>"
}
Required
Property | Value | 类型 | Description |
---|---|---|---|
method |
< method-type> | String | 用于发送传出请求的方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
uri |
< HTTP-or-HTTPS-endpoint-URL> | String | 需在其中发送传出请求的 HTTP 或 HTTPS 终结点 URL。 最大字符串大小:2 KB 对于 Azure 服务或资源,此 URI 语法包括要访问的资源的资源 ID 和路径。 |
frequency |
< time-unit> | String | 用于描述触发器触发频率的时间单位:“秒”、“分钟”、“小时”、“天”、“周”、“月” |
interval |
< number-of-time-units> | Integer | 指定触发器触发频率的值,即触发器再次触发之前需等待的时间单位数 下面是最小和最大间隔: - 月:1-16 个月 - 天:1-500 天 - 小时:1-12,000 小时 - 分钟:1-72,000 分钟 - 秒:1-9,999,999 秒 例如,如果间隔为 6,频率为“月”,则重复周期为每 6 个月。 |
Optional
Property | Value | 类型 | Description |
---|---|---|---|
headers |
< header-content> | JSON Object | 需包括在请求中的任何标头 例如,设置语言和类型: "headers": { "Accept-Language": "en-us", "Content-Type": "application/json" } |
queries |
< query-parameters> | JSON Object | 需在请求中使用的任何查询参数 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到请求。 |
body |
< body-content> | JSON Object | 要作为有效负载与请求一同发送的消息内容 |
authentication |
< authentication-type-and-property-values> | JSON Object | 身份验证模型,请求用它对出站请求进行身份验证。 有关详细信息,请参阅针对出站调用添加身份验证。 除计划程序外,还支持 authority 属性。 如果未指定此值,则使用默认值 https://management.azure.com/ ,但也可使用其他值。 |
retryPolicy > type |
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
runs |
< max-runs> | Integer | By default, workflow instances run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
maximumWaitingRuns |
< max-runs-queue> | Integer | When your workflow is already running the maximum number of instances, which you can change based on the runtimeConfiguration.concurrency.runs property, any new runs are put into this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 |
operationOptions |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Outputs
Element | 类型 | Description |
---|---|---|
headers |
JSON Object | 响应的标头 |
body |
JSON Object | 响应的正文 |
status code |
Integer | 响应中的状态代码 |
传入请求的要求
为很好地配合逻辑应用进行工作,终结点必须符合特定触发器模式或协定,并识别以下响应属性:
Property | Required | Description |
---|---|---|
Status code | Yes | “200 OK”状态代码启动运行。 其他任何状态代码均不会启动运行。 |
Retry-after header | No | 逻辑应用再次轮询终结点之前所要经过的秒数 |
Location header | No | 在下一个轮询间隔要调用的 URL。 如果未指定,将使用原始 URL。 |
不同请求的示例行为
Status code | Retry after | Behavior |
---|---|---|
200 | {none} | 运行工作流,然后在定义的重复周期后再次检查是否有更多数据。 |
200 | 10 seconds | 运行工作流,然后在 10 秒后再次检查是否有更多数据。 |
202 | 60 seconds | 不会触发工作流。 下一次尝试将在一分钟后发生,也需要遵循定义的重复周期。 如果定义的重复周期不到一分钟,重试间隔标头优先。 否则,将使用定义的重复周期。 |
400 | {none} | 错误的请求,不会运行工作流。 如果未定义 retryPolicy ,将使用默认策略。 在达到重试次数后,触发器会在定义的重复周期后再次检查是否有数据。 |
500 | {none} | 服务器错误,不会运行工作流。 如果未定义 retryPolicy ,将使用默认策略。 在达到重试次数后,触发器会在定义的重复周期后再次检查是否有数据。 |
HTTPWebhook trigger
此触发器创建一个可通过调用指定终结点 URL 来注册订阅的终结点,使逻辑应用可被调用。 在工作流中创建此触发器时,传出请求会进行调用以注册订阅。 这样,该触发器便可开始侦听事件。 当某个操作使该触发器无效时,传出请求会自动进行调用以取消订阅。 For more information, see Endpoint subscriptions.
You can also specify asynchronous limits on an HTTPWebhook trigger. 该触发器的行为取决于使用或省略的部分。
"HTTP_Webhook": {
"type": "HttpWebhook",
"inputs": {
"subscribe": {
"method": "<method-type>",
"uri": "<endpoint-subscribe-URL>",
"headers": { "<header-content>" },
"body": "<body-content>",
"authentication": { "<authentication-type>" },
"retryPolicy": { "<retry-behavior>" }
},
"unsubscribe": {
"method": "<method-type>",
"url": "<endpoint-unsubscribe-URL>",
"headers": { "<header-content>" },
"body": "<body-content>",
"authentication": { "<authentication-type>" }
}
},
"runTimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-runs-queue>
}
},
"operationOptions": "<operation-option>"
}
Some values, such as <method-type>, are available for both the "subscribe"
and "unsubscribe"
objects.
Required
Value | 类型 | Description |
---|---|---|
< method-type> | String | 用于订阅请求的 HTTP 方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
< endpoint-subscribe-URL> | String | 要将订阅请求发送到的终结点 URL |
Optional
Value | 类型 | Description |
---|---|---|
< method-type> | String | 用于取消请求的 HTTP 方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
< endpoint-unsubscribe-URL> | String | 要将取消请求发送到的终结点 URL |
< body-content> | String | 要在订阅请求或取消订阅请求中发送的任何消息内容 |
< authentication-type> | JSON Object | 身份验证模型,请求用它对出站请求进行身份验证。 有关详细信息,请参阅针对出站调用添加身份验证。 |
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
< max-runs> | Integer | By default, workflow instances all run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
< max-runs-queue> | Integer | When your workflow is already running the maximum number of instances, which you can change based on the runtimeConfiguration.concurrency.runs property, any new runs are put into this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Outputs
Element | 类型 | Description |
---|---|---|
headers | JSON Object | 响应的标头 |
body | JSON Object | 响应的正文 |
状态代码 | Integer | 响应中的状态代码 |
Example
此触发器创建指定终结点的订阅,提供唯一的回叫 URL,并等待新发布的技术文章。
"HTTP_Webhook": {
"type": "HttpWebhook",
"inputs": {
"subscribe": {
"method": "POST",
"uri": "https://pubsubhubbub.appspot.com/subscribe",
"body": {
"hub.callback": "@{listCallbackUrl()}",
"hub.mode": "subscribe",
"hub.topic": "https://pubsubhubbub.appspot.com/articleCategories/technology"
},
},
"unsubscribe": {
"method": "POST",
"url": "https://pubsubhubbub.appspot.com/subscribe",
"body": {
"hub.callback": "@{workflow().endpoint}@{listCallbackUrl()}",
"hub.mode": "unsubscribe",
"hub.topic": "https://pubsubhubbub.appspot.com/articleCategories/technology"
}
}
}
}
Recurrence trigger
此触发器的运行基于指定的重复计划,借助它可轻松创建定期运行的工作流。
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>,
"startTime": "<start-date-time-with-format-YYYY-MM-DDThh:mm:ss>",
"timeZone": "<time-zone>",
"schedule": {
// Applies only when frequency is Day or Week. Separate values with commas.
"hours": [ <one-or-more-hour-marks> ],
// Applies only when frequency is Day or Week. Separate values with commas.
"minutes": [ <one-or-more-minute-marks> ],
// Applies only when frequency is Week. Separate values with commas.
"weekDays": [ "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday" ]
}
},
"runtimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-runs-queue>
}
},
"operationOptions": "<operation-option>"
}
Required
Value | 类型 | Description |
---|---|---|
< time-unit> | String | 用于描述触发器触发频率的时间单位:“秒”、“分钟”、“小时”、“天”、“周”、“月” |
< number-of-time-units> | Integer | 指定触发器触发频率的值,即触发器再次触发之前需等待的时间单位数 下面是最小和最大间隔: - 月:1-16 个月 - 天:1-500 天 - 小时:1-12,000 小时 - 分钟:1-72,000 分钟 - 秒:1-9,999,999 秒 例如,如果间隔为 6,频率为“月”,则重复周期为每 6 个月。 |
Optional
Value | 类型 | Description |
---|---|---|
< start-date-time-with-format-YYYY-MM-DDThh:mm:ss> | String | 采用以下格式的启动日期和时间: 如果指定时区,则为 YYYY-MM-DDThh:mm:ss -or- 如果不指定时区,则为 YYYY-MM-DDThh:mm:ssZ 例如,如果需要 2017 年 9 月 18 日下午 2:00,则指定“2017-09-18T14:00:00”并指定时区(如“太平洋标准时间”),或仅指定“2017-09-18T14:00:00Z”,而不指定时区。 Note: This start time has a maximum of 49 years in the future and must follow the ISO 8601 date time specification in UTC date time format, but without a UTC offset. 如果未指定时区,则必须在末尾添加字母“Z”(无空格)。 This "Z" refers to the equivalent nautical time. 对于简单计划,开始时间指首次运行时间;对于复杂计划,触发器的激发时间不会早于开始时间。 有关启动日期和时间的详细信息,请参阅创建和计划定期运行任务。 |
< time-zone> | String | Applies only when you specify a start time because this trigger doesn't accept UTC offset. 指定要应用的时区。 |
< one-or-more-hour-marks> | 整数或整数数组 | 如果为 frequency 指定“Day”或“Week”,可以从 0 到 23 范围内指定一个或多个整数(用逗号分隔),作为一天中要运行工作流的时间点。 例如,如果指定“10”、“12”和“14”,则会将上午 10 点、中午 12 点和下午 2 点作为小时标记。 |
< one-or-more-minute-marks> | 整数或整数数组 | 如果为 frequency 指定“Day”或“Week”,可以从 0 到 59 范围内指定一个或多个整数(用逗号分隔),作为要运行工作流的分钟。 例如,可以指定“30”作为分钟标记并使用前面示例中的当天小时时间,这样,便可以指定10:30 AM、12:30 PM 和 2:30 PM 作为开始时间。 |
weekDays | 字符串或字符串数组 | 如果 frequency 指定为“周”,则可以指定一天或多天(用逗号分隔)作为运行工作流的时间:“星期一”、“星期二”、“星期三”、“星期四”、“星期五”、“星期六”和“星期日” |
< max-runs> | Integer | By default, workflow instances all run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
< max-runs-queue> | Integer | When your workflow is already running the maximum number of instances, which you can change based on the runtimeConfiguration.concurrency.runs property, any new runs are put into this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Example 1
此基本重复触发器每日都会运行:
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"frequency": "Day",
"interval": 1
}
}
Example 2
可以指定激发触发器的启动日期和时间。 此重复触发器在指定日期启动,然后每日触发:
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"frequency": "Day",
"interval": 1,
"startTime": "2017-09-18T00:00:00Z"
}
}
Example 3
此重复触发器在 2017 年 9 月 9 日下午 2:00 启动,并在每周一上午 10:30、中午 12:30 和下午 2:30(太平洋标准时间)触发:
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"frequency": "Week",
"interval": 1,
"schedule": {
"hours": [ 10, 12, 14 ],
"minutes": [ 30 ],
"weekDays": [ "Monday" ]
},
"startTime": "2017-09-07T14:00:00",
"timeZone": "Pacific Standard Time"
}
}
有关此触发器的详细信息和示例,请参阅创建和计划定期运行任务。
Request trigger
该触发器通过创建可接受传入请求的终结点,使逻辑应用可被调用。 对于此终结点,提供一个用于描述和验证触发器从传入请求接收的有效负载或输入的 JSON 架构。 此架构还使触发器属性更易于从工作流的后续操作中引用。
Note
The original name for the Request trigger was manual, which might still appear in some places. 此名称已更改,以围绕使用触发器生成的工作流模式类型创建更多一致性。
若要调用此触发器,必须使用 listCallbackUrl
API,工作流服务 REST API 中对此 API 进行了说明。 若要了解如何将此触发器用作 HTTP 终结点,请参阅使用 HTTP 终结点调用、触发或嵌套工作流。
"Request": {
"type": "Request",
"kind": "Http",
"inputs": {
"method": "<method-type>",
"relativePath": "<relative-path-for-accepted-parameter>",
"schema": {
"type": "object",
"properties": {
"<property-name>": {
"type": "<property-type>"
}
},
"required": [ "<required-properties>" ]
}
},
"runTimeConfiguration": {
"concurrency": {
"runs": <max-runs>,
"maximumWaitingRuns": <max-run-queue>
},
},
"operationOptions": "<operation-option>"
}
Required
Value | 类型 | Description |
---|---|---|
< property-name> | String | JSON 架构中属性的名称,描述有效负载 |
< property-type> | String | 属性的类型 |
Optional
Value | 类型 | Description |
---|---|---|
< method-type> | String | 传入请求必须用以调用逻辑应用的方法:“GET”、“PUT”、“POST”、“PATCH”、“DELETE” |
< relative-path-for-accepted-parameter> | String | 终结点的 URL 可接受的参数的相对路径 |
< required-properties> | Array | 需要值的一个或多个属性 |
< max-runs> | Integer | By default, workflow instances all run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change trigger concurrency. |
< max-runs-queue> | Integer | When your workflow is already running the maximum number of instances, which you can change based on the runtimeConfiguration.concurrency.runs property, any new runs are put into this queue up to the default limit. 若要更改此默认限制,请参阅更改等待的运行限制。 |
< operation-option> | String | 通过设置 operationOptions 属性可更改默认行为。 For more information, see Operation options. |
Example
此触发器指定传入请求必须使用 HTTP POST 方法调用触发器,并且包含验证传入请求输入的架构:
"Request": {
"type": "Request",
"kind": "Http",
"inputs": {
"method": "POST",
"schema": {
"type": "object",
"properties": {
"customerName": {
"type": "String"
},
"customerAddress": {
"type": "Object",
"properties": {
"streetAddress": {
"type": "string"
},
"city": {
"type": "string"
}
}
}
}
}
}
}
Trigger conditions
对于任何触发器且仅对于触发器,可包括一个数组,其中包含一个或多个决定工作流是否应该运行的条件表达式。 若要将 conditions
属性添加到工作流中的触发器,请在代码视图编辑器中打开逻辑应用。
例如,可通过引用 conditions
属性中触发器的状态代码,指定触发器仅在站点返回内部服务器错误时触发:
"Recurrence": {
"type": "Recurrence",
"recurrence": {
"frequency": "Hour",
"interval": 1
},
"conditions": [ {
"expression": "@equals(triggers().code, 'InternalServerError')"
} ]
}
默认情况下,触发器仅在获得“200 OK”响应后触发。 当表达式引用触发器的状态代码时,将替换触发器的默认行为。 因此,若要触发器针对多个状态代码(例如状态代码“200”和“201”)触发,必须包含此表达式作为条件:
@or(equals(triggers().code, 200),equals(triggers().code, 201))
在数组上触发多个运行
触发器可能会接收一个可供工作流处理的数组,但有时候,“for each”循环可能会花过长的时间来处理每个数组项。 Instead, you can use the SplitOn property in your trigger to debatch the array. 解除批处理时会拆分数组项,并启动一个针对每个数组项来运行的新工作流实例。 多种情况下可以使用此方法。例如,需要轮询一个终结点,而该终结点可能在不同的轮询间隔期之间返回多个新项。
If your trigger's Swagger file describes a payload that's an array, the SplitOn property is automatically added to your trigger. 否则,请将此属性添加到其数组需要解除批处理的响应有效负载中。
在使用 SplitOn 功能之前,请查看以下注意事项:
If trigger concurrency is enabled, the SplitOn limit is significantly reduced. 如果项数超过此限制,会禁用 SplitOn 功能。
无法对同步响应模式使用 SplitOn 功能。 Any workflow that uses the SplitOn property and includes a response action runs asynchronously and immediately sends a
202 ACCEPTED
response.For the maximum number of array items that SplitOn can process in a single workflow run, see Limits and configuration.
Example
假设有一个 HTTP 触发器,该触发器调用 API 并接收此响应:
{
"Status": "Succeeded",
"Rows": [
{
"id": 938109380,
"name": "customer-name-one"
},
{
"id": 938109381,
"name": "customer-name-two"
}
]
}
工作流只需要 Rows
中的数组的内容,因此,可以按以下示例所示创建触发器:
"HTTP_Debatch": {
"type": "Http",
"inputs": {
"uri": "https://mydomain.com/myAPI",
"method": "GET"
},
"recurrence": {
"frequency": "Second",
"interval": 1
},
"splitOn": "@triggerBody()?.Rows"
}
Note
如果使用 SplitOn
命令,则无法获取数组外部的属性。
因此,就此示例来说,不能在从 API 返回的响应中获取 status
属性。
为了避免在不存在 Rows
属性的情况下发生故障,本示例使用了 ?
运算符。
工作流定义现在可以使用 @triggerBody().name
获取 name
值,即第一个运行中的 "customer-name-one"
和第二个运行中的 "customer-name-two"
。 因此,触发器的输出如以下示例所示:
{
"body": {
"id": 938109380,
"name": "customer-name-one"
}
}
{
"body": {
"id": 938109381,
"name": "customer-name-two"
}
}
Actions overview
Azure 逻辑应用提供多种操作类型,每个类型均具有定义操作的唯一行为的不同输入。 操作具有以下高级元素,但有一些是可选元素:
"<action-name>": {
"type": "<action-type>",
"inputs": {
"<input-name>": { "<input-value>" },
"retryPolicy": "<retry-behavior>"
},
"runAfter": { "<previous-trigger-or-action-status>" },
"runtimeConfiguration": { "<runtime-config-options>" },
"operationOptions": "<operation-option>"
},
Required
Value | 类型 | Description |
---|---|---|
< action-name> | String | 操作的名称 |
< action-type> | String | 操作类型,例如“Http”或“ApiConnection” |
< input-name> | String | 定义操作行为的输入的名称 |
< input-value> | Various | 输入值,可为字符串、整数、JSON 对象等 |
< previous-trigger-or-action-status> | JSON Object | 在此当前操作可以运行之前,必须立即运行的触发器或操作的名称和结果状态 |
Optional
Value | 类型 | Description |
---|---|---|
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 有关详细信息,请参阅“重试策略”。 |
< runtime-config-options> | JSON Object | 对于某些操作,可通过设置 runtimeConfiguration 属性在运行时更改操作的行为。 有关详细信息,请参阅运行时配置设置。 |
< operation-option> | String | 对于某些操作,可通过设置 operationOptions 属性更改默认行为。 For more information, see Operation options. |
操作类型列表
以下为一些常用操作类型:
内置操作类型,例如以下示例等:
HTTP for calling endpoints over HTTP or HTTPS
Response for responding to requests
执行 JavaScript 代码以运行 JavaScript 代码片段
Function for calling Azure Functions
Data operation actions such as Join, Compose, Table, Select, and others that create or transform data from various inputs
Workflow for calling another logic app workflow
托管的 API 操作类型,例如调用由 Microsoft 托管的各种连接器和 API(例如 Azure 服务总线、Office 365 Outlook、Power BI、Azure Blob 存储、OneDrive 和 GitHub 等)的 ApiConnection 和 ApiConnectionWebHook
包含其他操作且有助于整理工作流执行的控制工作流操作类型,例如 If、Foreach、Switch、Scope 和 Until
Built-in actions
Action type | Description |
---|---|
Compose | 从输入创建单个输出,可具有多种类型。 |
执行 JavaScript 代码 | 运行符合特定条件的 JavaScript 代码片段。 有关代码要求和详细信息,请参阅添加并运行包含内联代码的代码片段。 |
Function | 调用 Azure Function。 |
HTTP | 调用 HTTP 终结点。 |
Join | 基于数组中的所有项创建一个字符串,并使用指定的分隔符字符分隔这些项。 |
Parse JSON | 基于 JSON 内容中的属性创建用户友好型令牌。 然后可通过将令牌包含在逻辑应用中来引用这些属性。 |
Query | 基于条件或筛选器使用另一个数组中的项创建数组。 |
Response | 创建针对传入调用或请求的响应。 |
Select | 通过基于指定映射转换另一个数组中的项,使用 JSON 对象创建数组。 |
Table | 根据数组创建 CSV 或 HTML 表。 |
Terminate | 停止正在主动运行的工作流。 |
Wait | 将工作流暂停指定的时间段或暂停到指定日期和时间。 |
Workflow | 将一个工作流嵌套在另一个工作流内。 |
托管的 API 操作
Action type | Description |
---|---|
ApiConnection | Calls an HTTP endpoint by using a Microsoft-managed API. |
ApiConnectionWebhook | Works like HTTP Webhook but uses a Microsoft-managed API. |
控制工作流操作
这些操作有助于控制工作流执行且包含其他操作。 从某一控制工作流操作外部,可直接引用该控制工作流操作内的操作。 例如,假如你在某一范围内拥有一个 Http
操作,则可从此工作流任意位置引用 @body('Http')
表达式。 但是,控制工作流操作内部存在的操作仅可在相同控制工作流结构中的其他操作“之后运行”。
Action type | Description |
---|---|
ForEach | 在循环中对数组中的每个项执行相同的操作。 |
If | 基于指定条件为 true 还是为 false 来运行操作。 |
Scope | 基于组状态从一组操作中运行操作。 |
Switch | 当表达式、对象或令牌的值匹配各事例指定的值时,运行被组织为事例的操作。 |
Until | 在循环中运行操作,直至指定条件为 true。 |
操作 - 详细参考
APIConnection action
This action sends an HTTP request to a Microsoft-managed API and requires information about the API and parameters plus a reference to a valid connection.
"<action-name>": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['<api-name>']['connectionId']"
},
"<other-action-specific-input-properties>"
},
"method": "<method-type>",
"path": "/<api-operation>",
"retryPolicy": "<retry-behavior>",
"queries": { "<query-parameters>" },
"<other-action-specific-properties>"
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< action-name> | String | 连接器提供的操作的名称 |
< api-name> | String | 用于连接的 Microsoft 托管 API 的名称 |
< method-type> | String | 用于调用 API 的 HTTP 方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
< api-operation> | String | 要调用的 API 操作 |
Optional
Value | 类型 | Description |
---|---|---|
< other-action-specific-input-properties> | JSON Object | 应用于此指定操作的任何其他输入属性 |
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
< query-parameters> | JSON Object | 要包括在 API 调用中的任何查询参数。 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
< other-action-specific-properties> | JSON Object | 应用于此指定操作的任何其他属性 |
Example
此定义演示 Office 365 Outlook 连接器(属于 Microsoft 托管 API)的“发送电子邮件”操作:
"Send_an_email": {
"type": "ApiConnection",
"inputs": {
"body": {
"Body": "Thank you for your membership!",
"Subject": "Hello and welcome!",
"To": "Sophie.Owen@contoso.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "POST",
"path": "/Mail"
},
"runAfter": {}
}
APIConnectionWebhook action
This action sends a subscription request over HTTP to an endpoint by using a Microsoft-managed API, provides a callback URL to where the endpoint can send a response, and waits for the endpoint to respond. For more information, see Endpoint subscriptions.
"<action-name>": {
"type": "ApiConnectionWebhook",
"inputs": {
"subscribe": {
"method": "<method-type>",
"uri": "<api-subscribe-URL>",
"headers": { "<header-content>" },
"body": "<body-content>",
"authentication": { "<authentication-type>" },
"retryPolicy": "<retry-behavior>",
"queries": { "<query-parameters>" },
"<other-action-specific-input-properties>"
},
"unsubscribe": {
"method": "<method-type>",
"uri": "<api-unsubscribe-URL>",
"headers": { "<header-content>" },
"body": "<body-content>",
"authentication": { "<authentication-type>" },
"<other-action-specific-properties>"
},
},
"runAfter": {}
}
Some values, such as <method-type>, are available for both the "subscribe"
and "unsubscribe"
objects.
Required
Value | 类型 | Description |
---|---|---|
< action-name> | String | 连接器提供的操作的名称 |
< method-type> | String | 用于从终结点订阅或取消订阅的 HTTP 方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
< api-subscribe-URL> | String | 用于订阅 API 的 URI |
Optional
Value | 类型 | Description |
---|---|---|
< api-unsubscribe-URL> | String | 用于取消订阅 API 的 URI |
< header-content> | JSON Object | 请求中发送的任何标头 例如,若要在请求中设置语言和类型: "headers": { "Accept-Language": "en-us", "Content-Type": "application/json" } |
< body-content> | JSON Object | 请求中发送的任何消息内容 |
< authentication-type> | JSON Object | 身份验证模型,请求用它对出站请求进行身份验证。 有关详细信息,请参阅针对出站调用添加身份验证。 |
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
< query-parameters> | JSON Object | 要包括在 API 调用中的任何查询参数 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
< other-action-specific-input-properties> | JSON Object | 应用于此指定操作的任何其他输入属性 |
< other-action-specific-properties> | JSON Object | 应用于此指定操作的任何其他属性 |
You can also specify limits on an ApiConnectionWebhook action in the same way as HTTP asynchronous limits.
Compose action
此操作基于多个输入(包括表达式)创建一个单一输出。 输出和输入均可具有 Azure 逻辑应用本机支持的任何类型,例如数组、JSON 对象、XML 和二进制文件。 此操作的输出之后可用于其他操作。
"Compose": {
"type": "Compose",
"inputs": "<inputs-to-compose>",
"runAfter": {}
},
Required
Value | 类型 | Description |
---|---|---|
< inputs-to-compose> | Any | 用于创建一个单一输出的输入 |
Example 1
此操作定义合并 abcdefg
与尾随空格和值 1234
:
"Compose": {
"type": "Compose",
"inputs": "abcdefg 1234",
"runAfter": {}
},
以下为此操作创建的输出:
abcdefg 1234
Example 2
此操作定义合并包含 abcdefg
的字符串变量与包含 1234
的整数变量:
"Compose": {
"type": "Compose",
"inputs": "@{variables('myString')}@{variables('myInteger')}",
"runAfter": {}
},
以下为此操作创建的输出:
"abcdefg1234"
执行 JavaScript 代码操作
此操作运行一个 JavaScript 代码片段,并通过一个令牌返回可供后续操作引用的结果。
"Execute_JavaScript_Code": {
"type": "JavaScriptCode",
"inputs": {
"code": "<JavaScript-code-snippet>",
"explicitDependencies": {
"actions": [ <preceding-actions> ],
"includeTrigger": true
}
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< JavaScript-code-snippet> | Varies | 要运行的 JavaScript 代码。 有关代码要求和详细信息,请参阅在工作流中运行代码片段。 在 code 特性中,代码片段可以使用只读的 workflowContext 对象作为输入。 此对象中的子属性可让代码访问触发器和工作流中任何先前操作提供的输出。 有关 workflowContext 对象的详细信息,请参阅使用 workflowContext 对象引用触发器和操作结果。 |
在某些情况下是必需的
explicitDependencies
特性指定要将触发器和/或先前操作的结果显式包含为代码片段的依赖项。 有关添加这些依赖项的详细信息,请参阅将依赖项作为参数添加到内联代码操作。
对于 includeTrigger
特性,可以指定 true
或 false
值。
Value | 类型 | Description |
---|---|---|
< preceding-actions> | String array | 一个数组,其操作名称采用 JSON 格式作为依赖项。 Make sure to use the action names that appear in your workflow definition where action names use underscores (_), not spaces (" "). |
Example 1
此操作运行的代码将获取逻辑应用工作流的名称,并返回文本“Hello world from <逻辑应用名称>”作为结果。 在此示例中,代码通过只读的 workflowContext.workflow.name
对象访问 workflowContext
属性,以此引用工作流的名称。 有关使用 workflowContext
对象的详细信息,请参阅代码中的引用触发器和操作结果。
"Execute_JavaScript_Code": {
"type": "JavaScriptCode",
"inputs": {
"code": "var text = \"Hello world from \" + workflowContext.workflow.name;\r\n\r\nreturn text;"
},
"runAfter": {}
}
Example 2
此操作将运行当新电子邮件抵达 Outlook 帐户时触发的逻辑应用工作流中的代码。 该工作流还使用 Office 365 Outlook 的“发送审批电子邮件”操作,连同审批请求一起转发已收到的电子邮件中的内容。
该代码从电子邮件消息的 Body
属性提取电子邮件地址,并连同审批操作中的 SelectedOption
属性值一起返回这些地址。 该操作在 对象内的 actions
对象中显式包含发送审批电子邮件操作作为依赖项。
"Execute_JavaScript_Code": {
"type": "JavaScriptCode",
"inputs": {
"code": "var myResult = /(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))/g;\r\n\r\nvar email = workflowContext.trigger.outputs.body.Body;\r\n\r\nvar reply = workflowContext.actions.Send_approval_email.outputs.body.SelectedOption;\r\n\r\nreturn email.match(myResult) + \" - \" + reply;\r\n;",
"explicitDependencies": {
"actions": [
"Send_approval_email"
]
}
},
"runAfter": {}
}
Function action
This action calls a previously created Azure function.
"<Azure-function-name>": {
"type": "Function",
"inputs": {
"function": {
"id": "<Azure-function-ID>"
},
"method": "<method-type>",
"headers": { "<header-content>" },
"body": { "<body-content>" },
"queries": { "<query-parameters>" }
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< Azure-function-ID> | String | 要调用的 Azure 函数的资源 ID。 下面是此值的格式: "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group>/providers/Microsoft.Web/sites/<Azure-function-app-name>/functions/<Azure-function-name>" |
< method-type> | String | 用于调用函数的 HTTP 方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” 如果未指定,则默认方法为“POST”。 |
Optional
Value | 类型 | Description |
---|---|---|
< header-content> | JSON Object | 与调用一同发送的任何标头 例如,若要在请求中设置语言和类型: "headers": { "Accept-Language": "en-us", "Content-Type": "application/json" } |
< body-content> | JSON Object | 请求中发送的任何消息内容 |
< query-parameters> | JSON Object | 要包括在 API 调用中的任何查询参数 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
< other-action-specific-input-properties> | JSON Object | 应用于此指定操作的任何其他输入属性 |
< other-action-specific-properties> | JSON Object | 应用于此指定操作的任何其他属性 |
保存逻辑应用时,Azure 逻辑应用会对所引用的函数执行这些检查:
工作流必须具有该函数的访问权限。
工作流只能使用标准 HTTP 触发器或泛型 JSON Webhook 触发器。
Azure 逻辑应用获取并缓存在运行时使用的触发器 URL。 However, if any operation invalidates the cached URL, the Function action fails at runtime. 若要解决此问题,请再次保存逻辑应用,以便逻辑应用再次获取和缓存此触发器 URL。
函数不能定义任何路由。
仅允许“函数”和“匿名”授权级别。
Example
此操作定义调用先前创建的“GetProductID”函数:
"GetProductID": {
"type": "Function",
"inputs": {
"function": {
"id": "/subscriptions/<XXXXXXXXXXXXXXXXXXXX>/resourceGroups/myLogicAppResourceGroup/providers/Microsoft.Web/sites/InventoryChecker/functions/GetProductID"
},
"method": "POST",
"headers": {
"x-ms-date": "@utcnow()"
},
"body": {
"Product_ID": "@variables('ProductID')"
}
},
"runAfter": {}
}
HTTP action
此操作向指定的 HTTP 或 HTTPS 终结点发送请求并检查响应,以确定工作流是否在运行。 有关详细信息,请参阅从 Azure 逻辑应用通过 HTTP 或 HTTPS 调用服务终结点。
"HTTP": {
"type": "Http",
"inputs": {
"method": "<method-type>",
"uri": "<HTTP-or-HTTPS-endpoint-URL>",
"headers": { "<header-content>" },
"queries": { "<query-parameters>" },
"body": "<body-content>",
"authentication": { "<authentication-type-and-property-values>" },
"retryPolicy": {
"type": "<retry-behavior>"
},
},
"runAfter": {}
}
Required
Property | Value | 类型 | Description |
---|---|---|---|
method |
< method-type> | String | 用于发送传出请求的方法:“GET”、“PUT”、“POST”、“PATCH”或“DELETE” |
uri |
< HTTP-or-HTTPS-endpoint-URL> | String | 需在其中发送传出请求的 HTTP 或 HTTPS 终结点 URL。 最大字符串大小:2 KB 对于 Azure 服务或资源,此 URI 语法包括要访问的资源的资源 ID 和路径。 |
Optional
Property | Value | 类型 | Description |
---|---|---|---|
headers |
< header-content> | JSON Object | 需包括在请求中的任何标头 例如,设置语言和类型: "headers": { "Accept-Language": "en-us", "Content-Type": "application/json" } |
queries |
< query-parameters> | JSON Object | 需在请求中使用的任何查询参数 例如, "queries": { "api-version": "2018-01-01" } 对象将 ?api-version=2018-01-01 添加到调用。 |
body |
< body-content> | JSON Object | 要作为有效负载与请求一同发送的消息内容 |
authentication |
< authentication-type-and-property-values> | JSON Object | 身份验证模型,请求用它对出站请求进行身份验证。 有关详细信息,请参阅针对出站调用添加身份验证。 除计划程序外,还支持 authority 属性。 如果未指定此值,则使用默认值 https://management.azure.com/ ,但也可使用其他值。 |
retryPolicy > type |
< retry-behavior> | JSON Object | 自定义状态代码为 408、429 和 5XX 的间歇性故障以及任何连接异常的重试行为。 For more information, see Retry policies. |
< other-action-specific-input-properties> | < input-property> | JSON Object | 应用于此指定操作的任何其他输入属性 |
< other-action-specific-properties> | < property-value> | JSON Object | 应用于此指定操作的任何其他属性 |
Example
此操作定义通过向指定终结点发送请求来获取最新资讯:
"HTTP": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "https://mynews.example.com/latest"
}
}
Join action
此操作基于数组中的所有项创建一个字符串,并使用指定的分隔符字符分隔这些项。
"Join": {
"type": "Join",
"inputs": {
"from": <array>,
"joinWith": "<delimiter>"
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< array> | Array | 提供源项的数组或表达式。 如果指定表达式,请将表达式括于双引号内。 |
< delimiter> | 单字符字符串 | 分隔字符串中每个项的字符 |
Example
假设先前已创建了一个包含此整数数组的“myIntegerArray”变量:
[1,2,3,4]
此操作定义通过在表达式中使用 variables()
函数来获取变量中的值,并使用这些值(以逗号隔开)创建此字符串:"1,2,3,4"
"Join": {
"type": "Join",
"inputs": {
"from": "@variables('myIntegerArray')",
"joinWith": ","
},
"runAfter": {}
}
Parse JSON 操作
This action creates user-friendly fields or tokens from the properties in JSON content. 之后可改用令牌在逻辑应用中访问这些属性。 例如,要使用 Azure 服务总线和 Azure Cosmos DB 等服务的 JSON 输出时,可将此操作包含在逻辑应用中,以便可更轻松地引用该输出中的数据。
"Parse_JSON": {
"type": "ParseJson",
"inputs": {
"content": "<JSON-source>",
"schema": { "<JSON-schema>" }
},
"runAfter": {}
},
Required
Value | 类型 | Description |
---|---|---|
< JSON-source> | JSON Object | 要分析的 JSON 内容 |
< JSON-schema> | JSON Object | 描述基础 JSON 内容的 JSON 架构,操作将该架构用于分析源 JSON 内容。 Tip: In the workflow designer, you can either provide the schema or provide a sample payload so that the action can generate the schema. |
Example
This action definition creates these tokens that you can use in your workflow but only in actions that run following the Parse JSON action:
FirstName
、LastName
和 Email
"Parse_JSON": {
"type": "ParseJson",
"inputs": {
"content": {
"Member": {
"Email": "Sophie.Owen@contoso.com",
"FirstName": "Sophie",
"LastName": "Owen"
}
},
"schema": {
"type": "object",
"properties": {
"Member": {
"type": "object",
"properties": {
"Email": {
"type": "string"
},
"FirstName": {
"type": "string"
},
"LastName": {
"type": "string"
}
}
}
}
}
},
"runAfter": { }
},
在此示例中,“content”属性指定操作要分析的 JSON 内容。 此外,还可提供此 JSON 内容作为生成该架构的相同有效负载。
"content": {
"Member": {
"FirstName": "Sophie",
"LastName": "Owen",
"Email": "Sophie.Owen@contoso.com"
}
},
“schema”属性指定用于描述 JSON 内容的 JSON 架构:
"schema": {
"type": "object",
"properties": {
"Member": {
"type": "object",
"properties": {
"FirstName": {
"type": "string"
},
"LastName": {
"type": "string"
},
"Email": {
"type": "string"
}
}
}
}
}
Query action
此操作基于指定条件或筛选器使用另一个数组中的项创建数组。
"Filter_array": {
"type": "Query",
"inputs": {
"from": <array>,
"where": "<condition-or-filter>"
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< array> | Array | 提供源项的数组或表达式。 如果指定表达式,请将表达式括于双引号内。 |
< condition-or-filter> | String | 用于筛选源数组中的项的条件 Note: If no values satisfy the condition, then the action creates an empty array. |
Example
此操作定义创建一个值大于指定值 2 的数组:
"Filter_array": {
"type": "Query",
"inputs": {
"from": [ 1, 3, 0, 5, 4, 2 ],
"where": "@greater(item(), 2)"
}
}
Response action
此操作创建 HTTP 请求响应的有效负载。
"Response" {
"type": "Response",
"kind": "http",
"inputs": {
"statusCode": 200,
"headers": { <response-headers> },
"body": { <response-body> }
},
"runAfter": {}
},
Required
Value | 类型 | Description |
---|---|---|
< response-status-code> | Integer | 发送到传入请求的 HTTP 状态代码。 默认代码为“200 OK”,但此代码可为以 2xx、4xx 或 5xx(非 3xxx)开头的任何有效状态代码。 |
Optional
Value | 类型 | Description |
---|---|---|
< response-headers> | JSON Object | 要包括在响应中的一个或多个标头 |
< response-body> | Various | 响应正文,可为字符串、JSON 对象甚至上一个操作的二进制内容 |
Example
此操作定义创建一个包含指定状态代码、消息正文和消息标头的 HTTP 请求响应:
"Response": {
"type": "Response",
"inputs": {
"statusCode": 200,
"body": {
"ProductID": 0,
"Description": "Organic Apples"
},
"headers": {
"x-ms-date": "@utcnow()",
"content-type": "application/json"
}
},
"runAfter": {}
}
Restrictions
Unlike other actions, the Response action has special restrictions:
Your workflow can use the Response action only when the workflow starts with an HTTP request trigger, meaning your workflow must be triggered by an HTTP request.
Your workflow can use the Response action anywhere except inside Foreach loops, Until loops, including sequential loops, and parallel branches.
The original request gets your workflow's response only when all actions required by the Response action are finished within the HTTP timeout limit.
但是,如果工作流调用另一个逻辑应用作为嵌套工作流,则父级工作流在嵌套工作流完成之前将处于等待状态,而不管嵌套工作流完成需要多久时间。
When your workflow uses the Response action and a synchronous response pattern, the workflow can't also use the splitOn command in the trigger definition because that command creates multiple runs. 使用 PUT 方法时请检查是否存在这种情况,如果为 true,则会返回“错误的请求”响应。
Otherwise, if your workflow uses the splitOn command and a Response action, the workflow runs asynchronously and immediately returns a "202 ACCEPTED" response.
When your workflow's execution reaches the Response action, but the incoming request has already received a response, the Response action is marked as "Failed" due to the conflict. 因此,逻辑应用运行也会被标记为“Failed”状态。
Select action
此操作通过基于指定映射转换另一个数组中的项,创建包含 JSON 对象的数组。 输出数组和源数组的项数始终相同。 虽然无法更改输出数组中的对象数,但可以添加或删除这些对象的属性以及属性值。
select
属性至少指定一个键值对,此键值对定义用于转换源数组中的项的映射。 键值对表示输出数组中所有对象的某个属性和该属性的值。
"Select": {
"type": "Select",
"inputs": {
"from": <array>,
"select": {
"<key-name>": "<expression>",
"<key-name>": "<expression>"
}
},
"runAfter": {}
},
Required
Value | 类型 | Description |
---|---|---|
< array> | Array | 提供源项的数组或表达式。 确保将表达式放入双引号内。 Note: If the source array is empty, the action creates an empty array. |
< key-name> | String | The property name assigned to the result from <expression> To add a new property across all objects in the output array, provide a <key-name> for that property and an <expression> for the property value. To remove a property from all objects in the array, omit the <key-name> for that property. |
< expression> | String | The expression that transforms the item in the source array and assigns the result to <key-name> |
The Select action creates an array as output, so any action that wants to use this output must either accept an array, or you must convert the array into the type that the consumer action accepts. For example, to convert the output array to a string, you can pass that array to the Compose action, and then reference the output from the Compose action in your other actions.
Example
此操作定义基于一个整数数组创建 JSON 对象数组。 此操作循环访问此源数组,使用 @item()
表达式获取每个整数值,然后将每个值分配给每个 JSON 对象中的“number
”属性:
"Select": {
"type": "Select",
"inputs": {
"from": [ 1, 2, 3 ],
"select": {
"number": "@item()"
}
},
"runAfter": {}
},
以下为此操作创建的数组:
[ { "number": 1 }, { "number": 2 }, { "number": 3 } ]
To use this array output in other actions, pass this output into a Compose action:
"Compose": {
"type": "Compose",
"inputs": "@body('Select')",
"runAfter": {
"Select": [ "Succeeded" ]
}
},
You can then use the output from the Compose action in your other actions, for example, the Office 365 Outlook - Send an email action:
"Send_an_email": {
"type": "ApiConnection",
"inputs": {
"body": {
"Body": "@{outputs('Compose')}",
"Subject": "Output array from Select and Compose actions",
"To": "<your-email@domain>"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {
"Compose": [ "Succeeded" ]
}
},
Table action
此操作根据数组创建 CSV 或 HTML 表。 对于包含 JSON 对象的数组,此操作根据对象的属性名称自动创建列标头。 对于包含其他数据类型的数组,必须指定列标头和值。 例如,此数组包含该操作可用于列标头名称的“ID”和“Product_Name”属性:
[ {"ID": 0, "Product_Name": "Apples"}, {"ID": 1, "Product_Name": "Oranges"} ]
"Create_<CSV | HTML>_table": {
"type": "Table",
"inputs": {
"format": "<CSV | HTML>",
"from": <array>,
"columns": [
{
"header": "<column-name>",
"value": "<column-value>"
},
{
"header": "<column-name>",
"value": "<column-value>"
}
]
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
<CSV or HTML> | String | 要创建的表的格式 |
< array> | Array | 为表提供源项的数组或表达式 Note: If the source array is empty, the action creates an empty table. |
Optional
若要指定或自定义列标头和值,请使用 columns
数组。
header-value
对具有相同标头名称时,其值显示在该标头名称下相同的列中。 否则,每个唯一的标头定义一个唯一列。
Value | 类型 | Description |
---|---|---|
< column-name> | String | 列的标头名称 |
< column-value> | Any | 该列中的值 |
Example 1
假设先前已创建了一个当前包含此数组的“myItemArray”变量:
[ {"ID": 0, "Product_Name": "Apples"}, {"ID": 1, "Product_Name": "Oranges"} ]
此操作定义根据“myItemArray”变量创建一个 CSV 表。
from
属性使用的表达式通过使用 variables()
函数从“myItemArray”获取数组:
"Create_CSV_table": {
"type": "Table",
"inputs": {
"format": "CSV",
"from": "@variables('myItemArray')"
},
"runAfter": {}
}
以下为此操作创建的 CSV 表:
ID,Product_Name
0,Apples
1,Oranges
Example 2
此操作定义根据“myItemArray”变量创建一个 HTML 表。
from
属性使用的表达式通过使用 variables()
函数从“myItemArray”获取数组:
"Create_HTML_table": {
"type": "Table",
"inputs": {
"format": "HTML",
"from": "@variables('myItemArray')"
},
"runAfter": {}
}
以下为此操作创建的 HTML 表:
ID | Product_Name |
---|---|
0 | Apples |
1 | Oranges |
Example 3
此操作定义根据“myItemArray”变量创建一个 HTML 表。 但是,本示例使用“Stock_ID”和“Description”替代默认列标头名称,并在“Description”列的值中添加了“Organic”一词。
"Create_HTML_table": {
"type": "Table",
"inputs": {
"format": "HTML",
"from": "@variables('myItemArray')",
"columns": [
{
"header": "Stock_ID",
"value": "@item().ID"
},
{
"header": "Description",
"value": "@concat('Organic ', item().Product_Name)"
}
]
},
"runAfter": {}
},
以下为此操作创建的 HTML 表:
Stock_ID | Description |
---|---|
0 | Organic Apples |
1 | Organic Oranges |
Terminate action
此操作停止运行工作流实例、取消正在进行的所有操作、跳过任何剩余的操作并返回指定的状态。 For example, you can use the Terminate action when your logic app must exit completely from an error state. This action doesn't affect already completed actions and can't appear inside Foreach and Until loops, including sequential loops.
"Terminate": {
"type": "Terminate",
"inputs": {
"runStatus": "<status>",
"runError": {
"code": "<error-code-or-name>",
"message": "<error-message>"
}
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< status> | String | 运行返回的状态:“失败”、“已取消”或者“已成功” |
Optional
仅当“runStatus”属性设置为“Failed”状态时,“runError”对象的属性才适用。
Value | 类型 | Description |
---|---|---|
< error-code-or-name> | String | 错误的代码或名称 |
< error-message> | String | 消息或文本,描述错误和应用用户可采取的任何操作 |
Example
此操作定义停止工作流运行,将运行状态设为“Failed”,并返回状态、错误代码和错误消息:
"Terminate": {
"type": "Terminate",
"inputs": {
"runStatus": "Failed",
"runError": {
"code": "Unexpected response",
"message": "The service received an unexpected response. Please try again."
}
},
"runAfter": {}
}
Wait action
此操作将工作流执行暂停指定时间间隔或暂停到指定时间(仅二者之一)。
Specified interval
"Delay": {
"type": "Wait",
"inputs": {
"interval": {
"count": <number-of-units>,
"unit": "<interval>"
}
},
"runAfter": {}
},
Specified time
"Delay_until": {
"type": "Wait",
"inputs": {
"until": {
"timestamp": "<date-time-stamp>"
}
},
"runAfter": {}
},
Required
Value | 类型 | Description |
---|---|---|
< number-of-units> | Integer | For the Delay action, the number of units to wait |
< interval> | String | For the Delay action, the interval to wait: "Second", "Minute", "Hour", "Day", "Week", "Month" |
< date-time-stamp> | String | For the Delay Until action, the date and time to resume execution. 该值必须使用 UTC 日期时间格式。 |
Example 1
此操作定义将工作流暂停 15 分钟:
"Delay": {
"type": "Wait",
"inputs": {
"interval": {
"count": 15,
"unit": "Minute"
}
},
"runAfter": {}
},
Example 2
此操作定义将工作流暂停到指定时间:
"Delay_until": {
"type": "Wait",
"inputs": {
"until": {
"timestamp": "2017-10-01T00:00:00Z"
}
},
"runAfter": {}
},
Workflow action
此操作调用先前创建的另一个逻辑应用,这意味着可以包含和重复使用其他逻辑应用工作流。 You can also use the outputs from the child or nested logic app in actions that follow the nested logic app, provided that the child logic app returns a response.
Azure 逻辑应用检查对要调用的触发器的访问权限,确保你有权访问该触发器。 此外,嵌套逻辑应用还必须满足以下条件:
A trigger makes the nested logic app callable, such as a Request or HTTP trigger
与父级逻辑应用相同的 Azure 订阅
To use the outputs from the nested logic app in your parent logic app, the nested logic app must have a Response action
"<nested-logic-app-name>": {
"type": "Workflow",
"inputs": {
"body": { "<body-content" },
"headers": { "<header-content>" },
"host": {
"triggerName": "<trigger-name>",
"workflow": {
"id": "/subscriptions/<Azure-subscription-ID>/resourceGroups/<Azure-resource-group>/providers/Microsoft.Logic/<nested-logic-app-name>"
}
}
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< nested-logic-app-name> | String | 要调用的逻辑应用的名称 |
< trigger-name> | String | 要调用的嵌套逻辑应用中的触发器的名称 |
< Azure-subscription-ID> | String | 嵌套逻辑应用的 Azure 订阅 ID |
< Azure-resource-group> | String | 嵌套逻辑应用的 Azure 资源组名称 |
Optional
Value | 类型 | Description |
---|---|---|
< header-content> | JSON Object | 与调用一同发送的任何标头 |
< body-content> | JSON Object | 与调用一同发送的任何消息内容 |
Outputs
此操作的输出基于嵌套应用的 Response 操作而有所不同。 如果嵌套逻辑应用不包含 Response 操作,则输出为空。
Example
“Start_search”操作成功完成后,此工作流操作定义调用名为“Get_product_information”的另一个逻辑应用(该逻辑应用在指定输入中传递):
"actions": {
"Start_search": { <action-definition> },
"Get_product_information": {
"type": "Workflow",
"inputs": {
"body": {
"ProductID": "24601",
},
"host": {
"id": "/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/InventoryManager-RG/providers/Microsoft.Logic/Get_product_information",
"triggerName": "Find_product"
},
"headers": {
"content-type": "application/json"
}
},
"runAfter": {
"Start_search": [ "Succeeded" ]
}
}
},
控制工作流操作详细信息
Foreach action
此循环操作循环访问数组并针对每个数组项执行操作。 默认情况下,“for each”循环可以多达最大循环数并行运行。 有关此最大值,请参阅限制和配置。了解如何创建“for each”循环。
"For_each": {
"type": "Foreach",
"actions": {
"<action-1>": { "<action-definition-1>" },
"<action-2>": { "<action-definition-2>" }
},
"foreach": "<for-each-expression>",
"runAfter": {},
"runtimeConfiguration": {
"concurrency": {
"repetitions": <count>
}
},
"operationOptions": "<operation-option>"
}
Required
Value | 类型 | Description |
---|---|---|
< action-1...n> | String | 在每个数组项上运行的操作的名称 |
< action-definition-1...n> | JSON Object | 运行的操作的定义 |
< for-each-expression> | String | 用于引用指定数组中每个项的表达式 |
Optional
Value | 类型 | Description |
---|---|---|
< count> | Integer | By default, the "for each" loop iterations run at the same time (concurrently or in parallel) up to the default limit. To change this limit by setting a new <count> value, see Change "for each" loop concurrency. |
< operation-option> | String | To run a "for each" loop sequentially, rather than in parallel, set either <operation-option> to Sequential or <count> to 1 , but not both. 有关详细信息,请参阅按顺序运行“for each”循环。 |
Example
此“for each”循环为数组中的每个项发送一封电子邮件,其中包含来自传入电子邮件的附件。 该循环将一封电子邮件(含附件)发送给审阅此附件的人员。
"For_each": {
"type": "Foreach",
"actions": {
"Send_an_email": {
"type": "ApiConnection",
"inputs": {
"body": {
"Body": "@base64ToString(items('For_each')?['Content'])",
"Subject": "Review attachment",
"To": "Sophie.Owen@contoso.com"
},
"host": {
"connection": {
"id": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {}
}
},
"foreach": "@triggerBody()?['Attachments']",
"runAfter": {}
}
To specify only an array that is passed as output from the trigger, this expression gets the <array-name> array from the trigger body. 为避免在不存在数组的情况下出现故障,该表达式使用 ?
运算符:
@triggerBody()?['<array-name>']
If action
This action, which is a conditional statement, evaluates an expression that represents a condition and runs a different branch based on whether the condition is true or false. 如果条件为 true,则该条件将标记为“Succeeded”状态。 了解如何创建条件语句。
"Condition": {
"type": "If",
"expression": { "<condition>" },
"actions": {
"<action-1>": { "<action-definition>" }
},
"else": {
"actions": {
"<action-2>": { "<action-definition" }
}
},
"runAfter": {}
}
Value | 类型 | Description |
---|---|---|
< condition> | JSON Object | 要评估的条件(可以为表达式) |
< action-1> | JSON Object | The action to run when <condition> evaluates to true |
< action-definition> | JSON Object | 操作的定义 |
< action-2> | JSON Object | The action to run when <condition> evaluates to false |
actions
或 else
对象中的操作会获取以下状态:
- "Succeeded":运行且成功
- "Failed":运行但失败
- "Skipped":未运行各自的分支
Example
此条件指定当整数变量值大于零时,工作流检查网站。 如果变量为零或小于零,则工作流检查另一个网站。
"Condition": {
"type": "If",
"expression": {
"and": [ {
"greater": [ "@variables('myIntegerVariable')", 0 ]
} ]
},
"actions": {
"HTTP - Check this website": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "http://this-url"
},
"runAfter": {}
}
},
"else": {
"actions": {
"HTTP - Check this other website": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "http://this-other-url"
},
"runAfter": {}
}
}
},
"runAfter": {}
}
条件如何使用表达式
下面是一些示例,显示了如何在条件中使用表达式:
JSON | Result |
---|---|
"expression": "@parameters('<hasSpecialAction>')" | 仅针对布尔表达式,该条件对任何评估结果为 true 的值进行传递。 若要将其他类型转换为布尔值,请使用以下函数: empty() 或 equals() 。 |
"expression": "@greater(actions('<action>').output.value, parameters('<threshold>'))" | For comparison functions, the action runs only when the output from <action> is more than the <threshold> value. |
"expression": "@or(greater(actions('<action>').output.value, parameters('<threshold>')), less(actions('<same-action>').output.value, 100))" | For logic functions and creating nested Boolean expressions, the action runs when the output from <action> is more than the <threshold> value or under 100. |
"expression": "@equals(length(actions('<action>').outputs.errors), 0)" | 可以使用数组函数检查该数组是否具有项。 仅当 errors 数组为空时才运行该操作。 |
Scope action
This action logically groups actions into scopes, which get their own status after the actions in that scope finish running. 然后,可使用该范围的状态确定是否运行其他操作。 了解如何创建范围。
"Scope": {
"type": "Scope",
"actions": {
"<inner-action-1>": {
"type": "<action-type>",
"inputs": { "<action-inputs>" },
"runAfter": {}
},
"<inner-action-2>": {
"type": "<action-type>",
"inputs": { "<action-inputs>" },
"runAfter": {}
}
}
}
Required
Value | 类型 | Description |
---|---|---|
< inner-action-1...n> | JSON Object | 在范围内运行的一个或多个操作 |
< action-inputs> | JSON Object | 每个操作的输入 |
Switch action
This action, also known as a switch statement, organizes other actions into cases, and assigns a value to each case, except for the default case if one exists. When your workflow runs, the Switch action compares the value from an expression, object, or token against the values specified for each case. If the Switch action finds a matching case, your workflow runs only the actions for that case. Each time the Switch action runs, either only one matching case exists or no matches exist. If no matches exist, the Switch action runs the default actions. 了解如何创建 switch 语句。
"Switch": {
"type": "Switch",
"expression": "<expression-object-or-token>",
"cases": {
"Case": {
"actions": {
"<action-name>": { "<action-definition>" }
},
"case": "<matching-value>"
},
"Case_2": {
"actions": {
"<action-name>": { "<action-definition>" }
},
"case": "<matching-value>"
}
},
"default": {
"actions": {
"<default-action-name>": { "<default-action-definition>" }
}
},
"runAfter": {}
}
Required
Value | 类型 | Description |
---|---|---|
< expression-object-or-token> | Varies | 要计算的表达式、JSON 对象或令牌 |
< action-name> | String | 要针对匹配事例运行的操作的名称 |
< action-definition> | JSON Object | 要针对匹配事例运行的操作的定义 |
< matching-value> | Varies | 要与计算结果比较的值 |
Optional
Value | 类型 | Description |
---|---|---|
< default-action-name> | String | 无匹配事例存在时要运行的默认操作的名称 |
< default-action-definition> | JSON Object | 无匹配事例存在时要运行的操作的定义 |
Example
此操作定义评估答复审核请求电子邮件的人员选择了“Approve”还是“Reject”。 Based on this choice, the Switch action runs the actions for the matching case, which is to send another email to the responder but with different wording in each case.
"Switch": {
"type": "Switch",
"expression": "@body('Send_approval_email')?['SelectedOption']",
"cases": {
"Case": {
"actions": {
"Send_an_email": {
"type": "ApiConnection",
"inputs": {
"Body": "Thank you for your approval.",
"Subject": "Response received",
"To": "Sophie.Owen@contoso.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {}
},
"case": "Approve"
},
"Case_2": {
"actions": {
"Send_an_email_2": {
"type": "ApiConnection",
"inputs": {
"Body": "Thank you for your response.",
"Subject": "Response received",
"To": "Sophie.Owen@contoso.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {}
},
"case": "Reject"
}
},
"default": {
"actions": {
"Send_an_email_3": {
"type": "ApiConnection",
"inputs": {
"Body": "Please respond with either 'Approve' or 'Reject'.",
"Subject": "Please respond",
"To": "Sophie.Owen@contoso.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {}
}
},
"runAfter": {
"Send_approval_email": [
"Succeeded"
]
}
}
Until action
此循环操作包含在指定条件为 true 之前一直运行的操作。 在运行所有其他操作后,此循环会最后检查此条件。 可在 "actions"
对象中包含多个操作,且该操作必须至少定义一个限制。 了解如何创建“until”循环。
"Until": {
"type": "Until",
"actions": {
"<action-name>": {
"type": "<action-type>",
"inputs": { "<action-inputs>" },
"runAfter": {}
},
"<action-name>": {
"type": "<action-type>",
"inputs": { "<action-inputs>" },
"runAfter": {}
}
},
"expression": "<condition>",
"limit": {
"count": <loop-count>,
"timeout": "<loop-timeout>"
},
"runAfter": {}
}
Value | 类型 | Description |
---|---|---|
< action-name> | String | 要在循环内运行的操作的名称 |
< action-type> | String | 要运行的操作类型 |
< action-inputs> | Various | 要运行的操作的输入 |
< condition> | String | 当循环中的所有操作都运行完成后要计算的条件或表达式 |
< loop-count> | Integer | 针对操作可运行的最大循环数的限制。 有关默认限制和最大限制的详细信息,请参阅 Azure 逻辑应用的限制和配置。 |
< loop-timeout> | String | 针对循环可运行的最长时间的限制。 默认 timeout 值为 PT1H ,即要求的 ISO 8601 格式。 |
Note
如果表达式依赖于 Until 循环中任何操作的输出,请确保考虑到该操作导致的任何失败。
Example
此循环操作定义向指定 URL 发送一个 HTTP 请求,直到满足以下某个条件:
- 该请求获得一个含有“200 OK”状态代码的响应。
- 该循环已运行 60 次。
- 该循环已运行一小时。
"Run_until_loop_succeeds_or_expires": {
"type": "Until",
"actions": {
"HTTP": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "http://myurl"
},
"runAfter": {}
}
},
"expression": "@equals(outputs('HTTP')['statusCode'], 200)",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {}
}
Webhook 和订阅
基于 Webhook 的触发器和操作不会定期检查终结点,而是等待这些终结点中的指定事件或数据。 These triggers and actions subscribe to the endpoints by providing a callback URL where the endpoint can send responses.
当工作流出现任何形式的更改时,都将发生 subscribe
调用,例如续订凭据或触发器或操作的输入参数发生更改时。 该调用使用与标准 HTTP 操作相同的参数。
当操作使得触发器或操作无效时,会自动发生 unsubscribe
调用,例如:
- 删除或禁用触发器。
- 删除或禁用工作流。
- 删除或禁用订阅。
为支持这些调用,@listCallbackUrl()
表达式为此触发器或操作返回唯一的“回叫 URL”。 此 URL 代表使用服务 REST API 的终结点的唯一标识符。 此函数的参数与 webhook 触发器或操作相同。
更改异步持续时间
对于触发器和操作,均可通过添加 limit.timeout
属性的方式将异步模式的持续时间限制为指定时间间隔。 这样,如果该指定间隔结束时操作尚未完成,则会使用 Cancelled
代码将操作的状态标记为 ActionTimedOut
。
timeout
属性使用 ISO 8601 格式。
"<trigger-or-action-name>": {
"type": "Workflow | Webhook | Http | ApiConnectionWebhook | ApiConnection",
"inputs": {},
"limit": {
"timeout": "PT10S"
},
"runAfter": {}
}
运行时配置设置
可通过向触发器或操作定义中添加以下 runtimeConfiguration
属性来更改触发器和操作的默认运行时行为。
Property | 类型 | Description | 触发器或操作 |
---|---|---|---|
runtimeConfiguration.concurrency.runs |
Integer | Change the default limit on the number of workflow instances that can run at the same time (concurrently or in parallel). 调整此值有助于限制后端系统接收的请求数。 将 runs 属性设置为 1 与将 operationOptions 属性设置为 SingleInstance 的作用相同。 可以设置其中任一属性,但不能同时设置二者。 若要更改此默认限制,请参阅更改触发器并发或按顺序触发实例。 |
All triggers |
runtimeConfiguration.concurrency.maximumWaitingRuns |
Integer | Change the default limit on the number of workflow instances that must wait to run when your logic app is already running the maximum concurrent instances. 若要更改此默认限制,请参阅更改等待的运行限制。 |
All triggers |
runtimeConfiguration.concurrency.repetitions |
Integer | Change the default limit on the number of "for each" loop iterations that can run at the same time (concurrently or in parallel). 将 repetitions 属性设置为 1 与将 operationOptions 属性设置为 SingleInstance 的作用相同。 可以设置其中任一属性,但不能同时设置二者。 若要更改默认限制,请参阅更改“for each”并发或按顺序运行“for each”循环。 |
Action: Foreach |
runtimeConfiguration.paginationPolicy.minimumItemCount |
Integer | For specific actions that support and have pagination turned on, this value specifies the minimum number of results to retrieve. 若要启用分页,请参阅使用分页获取批量数据、项或结果 |
Action: Varied |
runtimeConfiguration.secureData.properties |
Array | 在许多触发器和操作中,这些设置会向逻辑应用的运行历史记录隐藏输入和/或输出。 若要详细了解如何保护此数据,请参阅在运行历史记录中隐藏输入和输出。 |
大多数触发器和操作 |
runtimeConfiguration.staticResult |
JSON Object | For actions that support and have the static result setting turned on, the staticResult object has these attributes: - name ,引用当前操作的静态结果定义名称,该名称显示在逻辑应用工作流的 staticResults 特性中的 definition 特性内。 有关详细信息,请参阅静态结果 - 工作流定义语言的架构参考。 - staticResultOptions ,指定当前操作的静态结果是否为 Enabled 。 若要启用静态结果,请参阅通过设置静态结果来使用模拟数据测试逻辑应用 |
Action: Varied |
Operation options
可通过触发器或操作定义中的以下 operationOptions
属性更改触发器和操作的默认行为。
Operation option | 类型 | Description | 触发器或操作 |
---|---|---|---|
DisableAsyncPattern |
String | 以同步方式而非异步方式运行基于 HTTP 的操作。 若要设置此选项,请参阅同步运行操作。 |
Actions: ApiConnection, HTTP, Response |
IncludeAuthorizationHeadersInOutputs |
String | 对于启用 Microsoft Entra ID OAuth 的逻辑应用,若要授予对基于请求的触发器终结点的入站调用的访问权限,请在触发器输出中添加来自 OAuth 访问令牌的 Authorization 标头。 有关详细信息,请参阅在 Request 触发器输出中包含“Authorization”标头。 |
Triggers: Request, HTTP Webhook |
Sequential |
String | 每次运行一个“for each”循环迭代,而不是同时并行运行所有迭代。 此选项与将 runtimeConfiguration.concurrency.repetitions 属性设置为 1 的作用相同。 可以设置其中任一属性,但不能同时设置二者。 若要设置此选项,请参阅按顺序运行“for each”循环。 |
Action: Foreach |
SingleInstance |
String | 按顺序对每个逻辑应用实例运行此触发器,并在等待上一个活动运行完成后,再触发下一个逻辑应用实例。 此选项与将 runtimeConfiguration.concurrency.runs 属性设置为 1 的作用相同。 可以设置其中任一属性,但不能同时设置二者。 若要设置此选项,请参阅按顺序触发实例。 |
All triggers |
SuppressWorkflowHeaders |
String | 不要在出站请求中发送 x-ms-* 元数据头。 默认情况下,Azure 逻辑应用在头名称中包含带x-ms- 前缀的额外元数据头,作为出站请求的一部分。 但是,某些旧服务不会接受具有额外未知头的请求,从而导致请求失败。 |
Actions: HTTP, Function, APIManagement |
SuppressWorkflowHeadersOnResponse |
String | 不要在响应入站触发器请求时发送 x-ms-* 元数据头。 默认情况下,Azure 逻辑应用向入站请求发送响应,响应的头名称中包含带有x-ms- 前缀的额外元数据头。 但是,某些旧服务不会接受具有额外未知头的请求或响应,从而导致请求失败。 |
Triggers: Request, HTTP Webhook |
更改触发器并发
默认情况下,逻辑应用工作流实例全部(以并发或并行方式)同时运行。 此行为意味着,每个触发器实例会在上一个处于活动状态的工作流实例完成运行之前触发。 However, the number of concurrently running instances has a default limit. 当并发运行的工作流实例的数量达到此限制时,任何其他新实例都必须等待运行。 此限制可控制后端系统接收的请求数。
When you turn on the trigger's concurrency control, trigger instances run in parallel up to the default limit. 要更改此默认并发限制,可使用代码视图编辑器或工作流设计器,因为通过设计器更改并发设置会添加或更新基础触发器定义中的runtimeConfiguration.concurrency.runs
属性,反之亦然。 此属性控制可并行运行的新工作流实例的最大数目。
在触发器上启用并发之前,请查看以下注意事项:
启用并发控制后,无法禁用并发。
如果并发触发器运行的最大数目达到最大并行度,后续触发器运行可能会遇到限制或“429 - 请求过多”错误。 如果设置了处理 429 错误的重试策略,触发器可能会遇到重试和限制行为循环,导致处理新触发器请求时出现长时间延迟。
When concurrency is enabled, the SplitOn limit is significantly reduced for debatching arrays. 如果项数超过此限制,会禁用 SplitOn 功能。
启用并发后,长时间运行的逻辑应用实例可能会导致新的逻辑应用实例进入等待状态。 此状态会阻止 Azure 逻辑应用创建新实例,即使并发运行次数小于指定的最大并发运行次数,也会发生这种情况。
To interrupt this state, cancel the earliest instances that are still running.
On your logic app's menu, select Overview.
In the Runs history section, select the earliest instance that is still running, for example:
Tip
To view only instances that are still running, open the All list, and select Running.
在“逻辑应用运行”下,选择“取消运行”。
若要避免这种可能性,请为任何可能阻止这些运行的操作添加超时。 如果使用的是代码编辑器,请参阅更改异步持续时间。 否则,如果使用的是设计器,请执行以下步骤:
在逻辑应用工作流中,选择要在其中添加超时的操作。 In the action's upper-right corner, select the ellipses (...) button, and then select Settings.
Under Timeout, specify the timeout duration in ISO 8601 format.
若要按顺序运行逻辑应用,请使用代码视图编辑器或设计器将触发器的并发度设置为
1
。 请确保不要在代码视图编辑器中将触发器的operationOptions
属性也设置为SingleInstance
。 否则会出现验证错误。 有关详细信息,请参阅按顺序触发实例。
在代码视图中编辑
在基础触发器定义中,添加 runtimeConfiguration.concurrency.runs
属性,并根据触发器并发限制设置值。 若要按顺序运行工作流,请将属性值设置为 1
。
此示例将并发运行限制为 10 个实例:
"<trigger-name>": {
"type": "<trigger-name>",
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>,
},
"runtimeConfiguration": {
"concurrency": {
"runs": 10
}
}
}
有关详细信息,请参阅运行时配置设置。
在工作流设计器中编辑
In the trigger's upper-right corner, select the ellipses (...) button, and then select Settings.
Under Concurrency Control, set Limit to On.
将“并行度”滑块拖到所需值处。 To run your logic app sequentially, drag the slider value to 1.
更改“for each”并发
默认情况下,“for each”循环迭代全部同时(以并发或并行方式)运行。 此行为意味着每个迭代在上一个迭代完成运行之前开始运行。 However, the number of concurrently running iterations has a default limit. 当并发运行的迭代的数量达到此限制时,任何其他迭代都必须等待运行。
要更改此默认限制,可使用代码视图编辑器或工作流设计器,因为通过设计器更改并发设置会添加或更新基础“for each”操作定义中的runtimeConfiguration.concurrency.repetitions
属性,反之亦然。 此属性控制可并行运行的最大迭代数。
Note
如果通过设计器或代码视图编辑器将“for each”操作设为按顺序运行,请勿在代码视图编辑器中将此操作的 operationOptions
属性设置为 Sequential
。 否则会出现验证错误。 有关详细信息,请参阅按顺序运行“for each”循环。
在代码视图中编辑
在基础“for each”定义中添加或更新 runtimeConfiguration.concurrency.repetitions
属性,该属性可以有一个从 1
到 50
范围内的值。
以下示例将并发运行数限制为 10 个迭代:
"For_each" {
"type": "Foreach",
"actions": { "<actions-to-run>" },
"foreach": "<for-each-expression>",
"runAfter": {},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 10
}
}
}
有关详细信息,请参阅运行时配置设置。
在工作流设计器中编辑
In the For each action, from the upper-right corner, select the ellipses (...) button, and then select Settings.
Under Concurrency Control, set Concurrency Control to On.
将“并行度”滑块拖到所需值处。 To run your logic app sequentially, drag the slider value to 1.
更改等待的运行限制
默认情况下,逻辑应用工作流实例全部(以并发或并行方式)同时运行。 此行为意味着,每个触发器实例会在上一个处于活动状态的工作流实例完成运行之前触发。 However, a default limit exists on the number of concurrently running workflow instances. 当并发运行数达到此限制时,任何其他新工作流实例都必须等待运行。 A default limit also exists on the number of waiting workflow instances. 当等待的实例数达到此限制时,Azure 逻辑应用不再接受要运行的新工作流实例。 请求和 webhook 触发器返回 429 - 请求过多错误,并且重复的触发器会开始跳过轮询尝试。
可以更改触发器并发的默认限制以及等待的运行数的默认限制。 但是,此更改主要是通过减慢触发速度来缓解并发运行带来的压力。 例如,如果有轮询触发器,并且等待运行队列由于正在进行的运行而已满,Azure 逻辑应用会停止轮询。 如果工作流使用基于请求的触发器,并且等待运行队列已满,则 Azure 逻辑应用开始返回 429 错误。 在某些情况下,Azure 逻辑应用无法在不引入故障的情况下停止触发器轮询,并且会选择仍将此类运行添加到等待运行队列,而不会导致调用运行失败。
在基础触发器定义中添加 runtimeConfiguration.concurrency.maximumWaitingRuns
属性,该属性可以有一个从 1
到 100
范围内的值。
"<trigger-name>": {
"type": "<trigger-name>",
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>,
},
"runtimeConfiguration": {
"concurrency": {
"maximumWaitingRuns": 50
}
}
}
有关详细信息,请参阅运行时配置设置。
按顺序触发实例
若要仅在上一个实例完成运行后才运行每个逻辑应用工作流实例,请将此触发器设为按顺序运行。 可使用代码视图编辑器或工作流设计器,因为通过设计器更改并发设置还会添加或更新基础触发器定义中的runtimeConfiguration.concurrency.runs
属性,反之亦然。
Note
如果通过设计器或代码视图编辑器将触发器设为按顺序运行,请勿在代码视图编辑器中将触发器的 operationOptions
属性设置为 Sequential
。
否则会出现验证错误。
在代码视图中编辑
在触发器定义中,设置以下任一属性,但不可同时设置二者。
将 runtimeConfiguration.concurrency.runs
属性设为 1
:
"<trigger-name>": {
"type": "<trigger-name>",
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>,
},
"runtimeConfiguration": {
"concurrency": {
"runs": 1
}
}
}
-or-
将 operationOptions
属性设为 SingleInstance
:
"<trigger-name>": {
"type": "<trigger-name>",
"recurrence": {
"frequency": "<time-unit>",
"interval": <number-of-time-units>,
},
"operationOptions": "SingleInstance"
}
在工作流设计器中编辑
In the trigger's upper-right corner, select the ellipses (...) button, and then select Settings.
Under Concurrency Control, set Limit to On.
将“并行度”滑块拖到数字 。
按顺序运行“for each”循环
若要仅在上一迭代完成运行后才运行“for each”循环迭代,请将“for each”操作设为按顺序运行。 可使用代码视图编辑器或工作流设计器,因为通过设计器更改操作的并发还会添加或更新基础操作定义中的runtimeConfiguration.concurrency.repetitions
属性,反之亦然。
Note
如果通过设计器或代码视图编辑器将“for each”操作设为按顺序运行,请勿在代码视图编辑器中将此操作的 operationOptions
属性设置为 Sequential
。
否则会出现验证错误。
在代码视图中编辑
在操作定义中,设置以下任一属性,但不可同时设置二者。
将 runtimeConfiguration.concurrency.repetitions
属性设为 1
:
"For_each" {
"type": "Foreach",
"actions": { "<actions-to-run>" },
"foreach": "<for-each-expression>",
"runAfter": {},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
}
}
-or-
将 operationOptions
属性设为 Sequential
:
"For_each" {
"type": "Foreach",
"actions": { "<actions-to-run>" },
"foreach": "<for-each-expression>",
"runAfter": {},
"operationOptions": "Sequential"
}
在工作流设计器中编辑
In the For each action's upper-right corner, select the ellipses (...) button, and then select Settings.
Under Concurrency Control, set Concurrency Control to On.
将“并行度”滑块拖到数字 。
在同步操作模式下运行操作
默认情况下,Azure 逻辑应用中的 HTTP 操作和 APIConnection 操作遵循标准的异步操作模式,而响应操作则遵循同步操作模式。 The asynchronous pattern specifies that after an action calls or sends a request to the specified endpoint, service, system, or API, the receiver immediately returns a "202 ACCEPTED" response. 此代码确认接收方已接受请求,但尚未完成处理。 The response can include a location
header that specifies the URL and a refresh ID that the caller can use to continually poll or check the status for the asynchronous request until the receiver stops processing and returns a "200 OK" success response or other non-202 response. 有关详细信息,请参阅异步微服务集成强制实施微服务自治。
In the Logic App Designer, the HTTP action, APIConnection actions, and Response action have the Asynchronous Pattern setting. 启用后,此设置指定调用方不等待处理完成即可继续执行下一操作,但需继续检查状态直到处理停止。 如果禁用,则此设置指定调用方需等待处理完成才能继续执行下一操作。 若要查找此设置,请执行以下步骤:
On the HTTP action's title bar, select the ellipses (...) button, which opens the action's settings.
Find the Asynchronous Pattern setting.
在操作的基础 JavaScript 对象表示法 (JSON) 定义中,HTTP 操作和 APIConnection 操作隐式遵循异步操作模式。
在某些情况下,你可能希望操作改为遵循同步模式。 例如,当你使用 HTTP 操作时,你可能希望:
在这些情况下,可以使用以下选项使操作以同步模式运行:
将该操作的轮询版本替换为 Webhook 版本(如果可用)。
通过执行以下任一选项来禁用操作的异步行为:
在逻辑应用设计器中,关闭“异步模式”设置。
在操作的基础 JSON 定义中,添加
"DisableAsyncPattern"
操作选项。
Turn off Asynchronous Pattern setting
In the Logic App Designer, on the action's title bar, select the ellipses (...) button, which opens the action's settings.
Find the Asynchronous Pattern setting, turn the setting to Off if enabled, and select Done.
在操作的 JSON 定义中禁用异步模式
In the action's underlying JSON definition, add and set the "operationOptions" property to "DisableAsyncPattern"
under the action's "inputs"
section, for example:
"<some-long-running-action>": {
"type": "Http",
"inputs": { "<action-inputs>" },
"operationOptions": "DisableAsyncPattern",
"runAfter": {}
}
对触发器和操作进行身份验证
HTTP 和 HTTPS 终结点支持不同类型的身份验证。 根据用于发出访问这些终结点的出站调用或请求的触发器或操作,可以从各种不同的身份验证类型中进行选择。 有关详细信息,请参阅针对出站调用添加身份验证。
Next steps
- 详细了解工作流定义语言