请参阅 Application Integration 支持的连接器。
对公共 API 进行 REST 调用
使用“调用 REST 端点”任务,调用 https://mocktarget.apigee.net/json
,并将响应保存在 JSON 变量中。
代码示例
{
"triggerConfigs": [{
"label": "API Trigger",
"startTasks": [{
"taskId": "1"
}],
"properties": {
"Trigger name": "CallRestEndpointDemo_API_1"
},
"triggerType": "API",
"triggerNumber": "1",
"triggerId": "api_trigger/CallRestEndpointDemo_API_1"
}],
"taskConfigs": [{
"task": "GenericRestV2Task",
"taskId": "1",
"parameters": {
"throwError": {
"key": "throwError",
"value": {
"booleanValue": true
}
},
"responseBody": {
"key": "responseBody",
"value": {
"stringArray": {
"stringValues": ["$`Task_1_responseBody`$"]
}
}
},
"disableSSLValidation": {
"key": "disableSSLValidation",
"value": {
"booleanValue": false
}
},
"httpParams": {
"key": "httpParams"
},
"responseHeader": {
"key": "responseHeader",
"value": {
"stringArray": {
"stringValues": ["$`Task_1_responseHeader`$"]
}
}
},
"userAgent": {
"key": "userAgent",
"value": {
"stringValue": ""
}
},
"httpMethod": {
"key": "httpMethod",
"value": {
"stringValue": "GET"
}
},
"responseStatus": {
"key": "responseStatus",
"value": {
"stringArray": {
"stringValues": ["$`Task_1_responseStatus`$"]
}
}
},
"url": {
"key": "url",
"value": {
"stringValue": "https://mocktarget.apigee.net/json"
}
},
"urlFetchingService": {
"key": "urlFetchingService",
"value": {
"stringValue": "HARPOON"
}
},
"useSSL": {
"key": "useSSL",
"value": {
"booleanValue": false
}
},
"requestorId": {
"key": "requestorId",
"value": {
"stringValue": ""
}
},
"urlQueryStrings": {
"key": "urlQueryStrings"
},
"requestBody": {
"key": "requestBody",
"value": {
"stringValue": ""
}
},
"followRedirects": {
"key": "followRedirects",
"value": {
"booleanValue": true
}
},
"additionalHeaders": {
"key": "additionalHeaders"
}
},
"nextTasks": [{
"taskId": "2"
}],
"taskExecutionStrategy": "WHEN_ALL_SUCCEED",
"displayName": "Call REST Endpoint"
}, {
"task": "FieldMappingTask",
"taskId": "2",
"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\": \"$`Task_1_responseBody`$\"\n },\n \"transformationFunctions\": [{\n \"functionType\": {\n \"stringFunction\": {\n \"functionName\": \"TO_JSON\"\n }\n }\n }]\n }\n },\n \"outputField\": {\n \"referenceKey\": \"$OutputJson$\",\n \"fieldType\": \"JSON_VALUE\",\n \"cardinality\": \"OPTIONAL\"\n }\n }]\n}"
}
}
},
"taskExecutionStrategy": "WHEN_ALL_SUCCEED",
"displayName": "Data Mapping"
}],
"integrationParameters": [{
"key": "`Task_1_responseHeader`",
"dataType": "STRING_VALUE",
"displayName": "`Task_1_responseHeader`",
"isTransient": true,
"producer": "1_1"
}, {
"key": "`Task_1_responseBody`",
"dataType": "STRING_VALUE",
"displayName": "`Task_1_responseBody`",
"isTransient": true,
"producer": "1_1"
}, {
"key": "`Task_1_responseStatus`",
"dataType": "STRING_VALUE",
"displayName": "`Task_1_responseStatus`",
"isTransient": true,
"producer": "1_1"
}, {
"key": "OutputJson",
"dataType": "JSON_VALUE",
"displayName": "OutputJson",
"inputOutputType": "OUT"
}]
}
集成流程示例
下图显示了此集成代码示例的集成编辑器布局示例。
上传并运行示例集成
如需上传并运行示例集成,请按以下步骤操作:
- 将集成示例保存为系统上的 .json 文件。
- 在 Google Cloud 控制台中,前往 Application Integration 页面。
转到 Application Integration
- 在导航菜单中,点击集成。随即会出现集成列表页面。
- 选择现有集成,或通过点击创建集成来创建新的集成。
要创建新的集成,请执行以下操作:
- 在创建 Integrations对话框中输入名称和说明。
- 为集成选择一个区域。
- 为集成选择服务帐号。您随时可以在集成工具栏的 info 集成摘要窗格中更改或更新集成的服务帐号详细信息。
- 点击创建。
这将在集成编辑器中打开集成。
- 在集成编辑器中,点击 publish“上传/下载”菜单,然后选择上传集成。
- 在文件浏览器对话框中,选择您在第 1 步中保存的文件,然后点击 Open。
系统会使用上传的文件创建新版本的集成。
- 在集成编辑器中,点击测试。
- 点击测试集成。这将运行集成,并在 Test Integration 窗格中显示执行结果。