[英]Merging 1 or more ODATA responses into 1 JSON message in Azure Logic Apps
我需要一些建議如何處理以下案件。
我正在創建一個 API,這個 API 將調用 1 個或多個 SAP ODATA 服務。 從這些 ODATA 復雜響應中,我想創建自己的響應並將其返回給我的 API。
如何解決這個需求? 我一直在努力解決我發現的一些 FOR EACH 場景,但是在部署這些示例之后,邏輯應用程序由於某種原因掛起。
謝謝!
從我的結束復制后,這工作正常。 我將嘗試解釋我是如何實現您的要求的。 下面是我的 Logic 應用程序的整個流程。
考慮下面是我收到的兩個回復。
輸入 1
{
"firstName": "SampleFirstName",
"lastName": "SampleLastName"
}
輸入 2
{
"email": "sample@sample.com",
"Tasks": [
{
"TaskNo": "1",
"Date": "2022-08-25"
},
{
"TaskNo": "2",
"Date": "2022-08-25"
},
{
"TaskNo": "3",
"Date": "2022-08-25"
}
]
}
在下一步中,我將嘗試解析兩個輸入
下面是用於Parse JSON for Input-1
的 JSON 的 JSON 架構
{
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
},
"type": "object"
}
下面是用於Parse JSON for Input-2
的 JSON 的 JSON 架構
{
"properties": {
"Tasks": {
"items": {
"properties": {
"Date": {
"type": "string"
},
"TaskNo": {
"type": "string"
}
},
"required": [
"TaskNo",
"Date"
],
"type": "object"
},
"type": "array"
},
"email": {
"type": "string"
}
},
"type": "object"
}
您可以使用Use sample payload to generate schema
為 Parse JSON 操作生成自己的架構。
在下一步中,您可以使用Compose
操作來自定義構建 JSON。 下面是我如何合並兩個 JSON。
結果:
或者,您可以使用 Select 操作 map 對象
您可以使用下面的代碼視圖從您的端復制相同的內容。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Input-1": {
"inputs": {
"firstName": "SampleFirstName",
"lastName": "SampleLastName"
},
"runAfter": {},
"type": "Compose"
},
"Input-2": {
"inputs": {
"Tasks": [
{
"Date": "2022-08-25",
"TaskNo": "1"
},
{
"Date": "2022-08-25",
"TaskNo": "2"
},
{
"Date": "2022-08-25",
"TaskNo": "3"
}
],
"email": "sample@sample.com"
},
"runAfter": {
"Input-1": [
"Succeeded"
]
},
"type": "Compose"
},
"Merged_JSON": {
"inputs": {
"Tasks": "@body('Parse_JSON_for_Input-2')?['Tasks']",
"firstName": "@{body('Parse_JSON_for_Input-1')?['firstName']}",
"lastName": "@{body('Parse_JSON_for_Input-1')?['lastName']}"
},
"runAfter": {
"Parse_JSON_for_Input-2": [
"Succeeded"
]
},
"type": "Compose"
},
"Parse_JSON_for_Input-1": {
"inputs": {
"content": "@outputs('Input-1')",
"schema": {
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Input-2": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Parse_JSON_for_Input-2": {
"inputs": {
"content": "@outputs('Input-2')",
"schema": {
"properties": {
"Tasks": {
"items": {
"properties": {
"Date": {
"type": "string"
},
"TaskNo": {
"type": "string"
}
},
"required": [
"TaskNo",
"Date"
],
"type": "object"
},
"type": "array"
},
"email": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Parse_JSON_for_Input-1": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.