【发布时间】:2019-06-19 07:44:23
【问题描述】:
我想使用 Zapier 和 Webhooks 在两个不同的 CRM(Clevertap 和 Intercom)之间配置同步。一般来说,Clevertap 会向 webhook 发送以下 JSON:
{
"targetId": 1548328164,
"profiles": [
{
"event_properties": {
"MSG-sms": true,
"MSG-push": true,
"businessRole": "EMPLOYEE",
"Mobile Number": "123123123123",
"Name": "Artem Hovtvianisa",
"Title": "Mr",
"Last Name": "Hovtvianisa",
"Gender": "M",
"Customer type": "Business Account Holder",
"MSG-email": true,
"First Name": "Artem",
"Last seen IP": "111.177.74.50",
"tz": "GMT+0200",
"International customer": "yes",
"isBusiness": true,
"Email": "xxxyyy@gmail.com",
"Identity": 15675
},
"objectId": "e32e4de3c1e84b2d9bab3707c92cd092",
"all_identities": [
"15675",
"xxxyyy@gmail.com"
],
"email": "xxxyyy@gmail.com",
"identity": "15675"
}
]
}
Zapier 提供了两种类型的 catch webhook:regular 和 Raw。
抓住生钩
当我使用这种类型时,JSON 原始数据将被正常处理,并且在下一步(Zapier JS 代码应用程序)中,我能够像上面的示例一样传递正确的 JSON 数据。
但是,当我使用简单的 JS 代码解析 JSON 对象并获取配置文件 [0] 数组值时,我收到以下错误“TypeError: Cannot read property '0' of undefined”
代码步骤中的 JS 代码:
var result = JSON.parse(JSON.stringify(inputData));
console.log(result.profiles[0]);
return result;
抓钩
如果我使用常规的 Catch Hook,hook 会以某种奇怪的方式解析数据,如下所示:
JSON.parse 无法识别此结构。
请告知我如何以正确的方式处理 Webhook Zapier 步骤以获取配置文件 [0] 数组项值?
提前致谢!
【问题讨论】: