使用 get 和 body 参数调用嵌套的 Azure 逻辑应用
Call nested Azure logic app with get and body parameter
我们正在构建嵌套的逻辑应用程序,其中一个逻辑应用程序将调用另一个逻辑应用程序来聚合一些数据。
目前我们有逻辑应用 A
、B
和 C
都在使用 GET 请求进行设置。
聚合所有数据的逻辑应用程序 ABC
将通过 GET 请求由 API 公开,并在内部调用 A
到 C
以收集所有数据。
然而,当我们使用 Postman 时,我们收到一条错误消息:
{
"error": {
"code": "TriggerRequestMethodNotValid",
"message": "The HTTP method for this request is not valid: expected 'Get' and actual 'POST'."
}
}
这意味着 ABC
使用 POST 而不是 GET 调用 A
。
我们有预感,这是因为我们使用 body
元素调用逻辑应用程序。
我们通过将所有逻辑应用程序调用设置为 POST
暂时解决了该问题,但我们希望避免这种情况,因为我们可能会将 A
公开为系统层 API 并希望将其保留为获取。
A
的代码:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Filter_is_null": {
"actions": {
"Get_locations": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('Location__c'))}/items"
},
"runAfter": {},
"type": "ApiConnection"
},
"Response": {
"inputs": {
"body": "@body('Get_locations')?['value']",
"statusCode": 200
},
"kind": "Http",
"runAfter": {
"Get_locations": [
"Succeeded"
]
},
"type": "Response"
}
},
"else": {
"actions": {
"Get_locations_filtered": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('Location__c'))}/items",
"queries": {
"$filter": "@triggerBody()?['filter']"
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Response_error": {
"inputs": {
"body": {
"component": "sf-locations-get",
"message": "bad request - validate filter"
},
"statusCode": 400
},
"kind": "Http",
"runAfter": {
"Get_locations_filtered": [
"Failed"
]
},
"type": "Response"
},
"Response_filtered": {
"inputs": {
"body": "@body('Get_locations_filtered')?['value']",
"statusCode": 200
},
"runAfter": {
"Get_locations_filtered": [
"Succeeded"
]
},
"type": "Response"
}
}
},
"expression": {
"and": [
{
"equals": [
"@triggerBody()?['filter']",
"@null"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"request": {
"inputs": {
"method": "GET",
"schema": {
"properties": {
"filter": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
}
}
}
A
的图片供参考:
ABC
的图片供参考:
是否可以使用 GET 调用包含 body
的嵌套逻辑应用程序?
您可以从一个逻辑应用程序调用另一个逻辑应用程序并将 body 传递给它。
如果您正在调用另一个使用 http 请求触发的逻辑应用程序,则预期的方法通常是 POST。尝试通过 body 并检查是否对您的情况有帮助。
请参考这个document
您也可以查看这些是否满足您的要求:
在 GET 请求中使用 body 会破坏互联网。
简而言之,这打破了 resource-uri 与 headers 组合是可缓存键的语义。当您向 GET 请求添加 body 时,缓存功能将被删除。
根据设计,您不能也不应该向 GET 请求添加 body。
您应该重新考虑您的调用设置,当您需要发送 body 时,您需要使用其他不会破坏正确语义的 HTTP 方法。例如POST、PUT 等
我们正在构建嵌套的逻辑应用程序,其中一个逻辑应用程序将调用另一个逻辑应用程序来聚合一些数据。
目前我们有逻辑应用 A
、B
和 C
都在使用 GET 请求进行设置。
聚合所有数据的逻辑应用程序 ABC
将通过 GET 请求由 API 公开,并在内部调用 A
到 C
以收集所有数据。
然而,当我们使用 Postman 时,我们收到一条错误消息:
{
"error": {
"code": "TriggerRequestMethodNotValid",
"message": "The HTTP method for this request is not valid: expected 'Get' and actual 'POST'."
}
}
这意味着 ABC
使用 POST 而不是 GET 调用 A
。
我们有预感,这是因为我们使用 body
元素调用逻辑应用程序。
我们通过将所有逻辑应用程序调用设置为 POST
暂时解决了该问题,但我们希望避免这种情况,因为我们可能会将 A
公开为系统层 API 并希望将其保留为获取。
A
的代码:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Filter_is_null": {
"actions": {
"Get_locations": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('Location__c'))}/items"
},
"runAfter": {},
"type": "ApiConnection"
},
"Response": {
"inputs": {
"body": "@body('Get_locations')?['value']",
"statusCode": 200
},
"kind": "Http",
"runAfter": {
"Get_locations": [
"Succeeded"
]
},
"type": "Response"
}
},
"else": {
"actions": {
"Get_locations_filtered": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('Location__c'))}/items",
"queries": {
"$filter": "@triggerBody()?['filter']"
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Response_error": {
"inputs": {
"body": {
"component": "sf-locations-get",
"message": "bad request - validate filter"
},
"statusCode": 400
},
"kind": "Http",
"runAfter": {
"Get_locations_filtered": [
"Failed"
]
},
"type": "Response"
},
"Response_filtered": {
"inputs": {
"body": "@body('Get_locations_filtered')?['value']",
"statusCode": 200
},
"runAfter": {
"Get_locations_filtered": [
"Succeeded"
]
},
"type": "Response"
}
}
},
"expression": {
"and": [
{
"equals": [
"@triggerBody()?['filter']",
"@null"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"request": {
"inputs": {
"method": "GET",
"schema": {
"properties": {
"filter": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
}
}
}
A
的图片供参考:
ABC
的图片供参考:
是否可以使用 GET 调用包含 body
的嵌套逻辑应用程序?
您可以从一个逻辑应用程序调用另一个逻辑应用程序并将 body 传递给它。 如果您正在调用另一个使用 http 请求触发的逻辑应用程序,则预期的方法通常是 POST。尝试通过 body 并检查是否对您的情况有帮助。
请参考这个document
您也可以查看这些是否满足您的要求:
在 GET 请求中使用 body 会破坏互联网。
简而言之,这打破了 resource-uri 与 headers 组合是可缓存键的语义。当您向 GET 请求添加 body 时,缓存功能将被删除。
根据设计,您不能也不应该向 GET 请求添加 body。
您应该重新考虑您的调用设置,当您需要发送 body 时,您需要使用其他不会破坏正确语义的 HTTP 方法。例如POST、PUT 等