查看 Application Integration 支援的連接器

解析 JSON 參照

使用資料對應工作,在含有 $variable$ 參照的範本 JSON 中解析 JSON 參照。將輸出內容儲存在新的 JSON 變數中。

程式碼範例

{
  "triggerConfigs": [{
    "label": "API Trigger",
    "startTasks": [{
      "taskId": "1"
    }],
    "properties": {
      "Trigger name": "json_structure_mapping_API_1"
    },
    "triggerType": "API",
    "triggerNumber": "1",
    "triggerId": "api_trigger/json_structure_mapping_API_1"
  }],
  "taskConfigs": [{
    "task": "FieldMappingTask",
    "taskId": "1",
    "parameters": {
      "FieldMappingConfigTaskParameterKey": {
        "key": "FieldMappingConfigTaskParameterKey",
        "value": {
          "jsonValue": "{\n  \"@type\": \"type.googleapis.com/enterprise.crm.eventbus.proto.FieldMappingConfig\",\n  \"mappedFields\": [{\n    \"inputField\": {\n      \"fieldType\": \"JSON_VALUE\",\n      \"transformExpression\": {\n        \"initialValue\": {\n          \"referenceValue\": \"$new_structure_json_template$\"\n        },\n        \"transformationFunctions\": [{\n          \"functionType\": {\n            \"stringFunction\": {\n              \"functionName\": \"RESOLVE_TEMPLATE\"\n            }\n          }\n        }, {\n          \"functionType\": {\n            \"stringFunction\": {\n              \"functionName\": \"TO_JSON\"\n            }\n          }\n        }]\n      }\n    },\n    \"outputField\": {\n      \"referenceKey\": \"$output_order_json$\",\n      \"fieldType\": \"JSON_VALUE\",\n      \"cardinality\": \"OPTIONAL\"\n    }\n  }]\n}"
        }
      }
    },
    "taskExecutionStrategy": "WHEN_ALL_SUCCEED",
    "displayName": "Data Mapping"
  }],
  "integrationParameters": [{
    "key": "output_order_json",
    "dataType": "JSON_VALUE",
    "displayName": "output_order_json",
    "inputOutputType": "OUT"
  }, {
    "key": "new_structure_json_template",
    "dataType": "STRING_VALUE",
    "defaultValue": {
      "stringValue": "{\n\t\"order\": {\n\t\t\"ordDate\": \"$input_order_json.orderDate$\",\n\t\t\"orderID\": \"$input_order_json.orderNum$\",\n\t\t\"btAddr\": {\n\t\t\t\"btAddr\": \"$input_order_json.billTo.street$ $input_order_json.billTo.city$ $input_order_json.billTo.state$ $input_order_json.billTo.zipCode$\",\n\t\t\t\"btCode\": \"$input_order_json.billTo.billToCode$\"\n\t\t},\n\"stAddr\": {\n\t\t\t\"stAddress\": \"$input_order_json.shipTo.street$ $input_order_json.shipTo.city$ $input_order_json.shipTo.state$ $input_order_json.shipTo.zipCode$\",\n\t\t\t\"stCode\": \"$input_order_json.shipTo.shipToCode$\"\n\t\t}\n\t}\n}"
    },
    "displayName": "new_structure_json_template"
  }, {
    "key": "input_order_json",
    "dataType": "JSON_VALUE",
    "defaultValue": {
      "jsonValue": "{\n  \"orderNum\": \"123\",\n  \"orderDate\": \"29/5/2022\",\n  \"shipTo\": {\n    \"shipToCode\": \"CX3H-XC Sunnyvale, California\",\n    \"street\": \"1155 Borregas Ave\",\n    \"city\": \"Sunnyvale\",\n    \"state\": \"CA\",\n    \"zipCode\": \"94089\"\n  },\n  \"billTo\": {\n    \"billToCode\": \"CX3H+XC Sunnyvale, California\",\n    \"street\": \"1155 Borregas Ave\",\n    \"city\": \"Sunnyvale\",\n    \"state\": \"CA\",\n    \"zipCode\": \"94089\"\n  }\n}"
    },
    "displayName": "input_order_json",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"billTo\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"zipCode\": {\n          \"type\": \"string\"\n        },\n        \"city\": {\n          \"type\": \"string\"\n        },\n        \"street\": {\n          \"type\": \"string\"\n        },\n        \"state\": {\n          \"type\": \"string\"\n        },\n        \"billToCode\": {\n          \"type\": \"string\"\n        }\n      }\n    },\n    \"orderNum\": {\n      \"type\": \"string\"\n    },\n    \"orderDate\": {\n      \"type\": \"string\"\n    },\n    \"shipTo\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"zipCode\": {\n          \"type\": \"string\"\n        },\n        \"city\": {\n          \"type\": \"string\"\n        },\n        \"street\": {\n          \"type\": \"string\"\n        },\n        \"shipToCode\": {\n          \"type\": \"string\"\n        },\n        \"state\": {\n          \"type\": \"string\"\n        }\n      }\n    }\n  }\n}"
  }]
}

整合流程範例

下圖為此整合程式碼範例的整合編輯器範例版面配置。

顯示範例整合流程的圖片 顯示範例整合流程的圖片

上傳並執行範例整合

如要上傳及執行範例整合,請按照下列步驟操作:

  1. 整合範例儲存為系統上的 .json 檔案。
  2. 前往 Google Cloud 控制台的「Application Integration」頁面。

    前往「應用程式整合」

  3. 按一下左側導覽選單中的「整合」,開啟「整合」頁面。
  4. 選取現有的整合,或按一下「建立整合」來建立新的整合。

    如果您要建立新的整合功能:

    1. 在「Create Integration」對話方塊中輸入名稱和說明。
    2. 選取整合作業的區域。
    3. 選取要用於整合的服務帳戶。您隨時可以透過整合工具列的 「整合摘要」窗格,變更或更新整合作業的服務帳戶詳細資料。
    4. 按一下 [建立]。

    這會在整合編輯器中開啟整合。

  5. 整合服務編輯器中,按一下 「上傳/下載」選單,然後選取「上傳整合服務」
  6. 在檔案瀏覽器對話方塊中,選取您在步驟 1 中儲存的檔案,然後按一下「Open」

    系統會使用上傳的檔案建立新的整合版本。

  7. 整合服務編輯器中,按一下「測試」
  8. 按一下「測試整合」。這會執行整合作業,並在「Test Integration」窗格中顯示執行結果。