使用Zapier UI设置一个zap。
根据要求更新有关zap流的信息:
我有一个GET,它返回一个对象数组,然后我要查找是否有任何对象的ID与我的目标类别ID字符串匹配。如果选择inputData.categoryId,则无法获取整个数组。如果类别ID不在数组中,则需要采取措施。有没有办法将GET的整个有效负载传递到我的下一个代码操作步骤?
我尝试传递inputData.cateogryId,但是它为数组中的每个对象多次运行代码步骤。
我希望能够做到这样,其中inputData是GET的有效负载
const userRecords = JSON.parse(inputData);
output = {isNotSubscribed: false};
isNotSubscribed = userRecords.find(o => o.categoryId === 'string 1');
输入数据位于数组中,看起来像
[
{
"id": "string",
"identifier": "string",
"name": "string",
"description": "string",
"categoryId": "string",
"contentId": "string",
"signedDate": "2019-08-30T21:44:30.497Z",
},
{
"id": "string",
"identifier": "string",
"name": "string",
"description": "string",
"categoryId": "string",
"contentId": "string",
"signedDate": "2019-08-30T21:44:30.497Z",
},
{
"id": "string",
"identifier": "string",
"name": "string",
"description": "string",
"categoryId": "string",
"contentId": "string",
"signedDate": "2019-08-30T21:44:30.497Z",
}
]
答案 0 :(得分:1)
您应该考虑使用Python代码来代替“获取”使用Zapier UI。 Postman可以轻松地将您的请求从应用程序转换为Python代码。
如果这样做,则python“ GET”的输出将是dic数组。看起来应该像这样:
url ="yoururl"
params= {"key":"value"}
payload = {"key":"value"}
headers = {"key":"value"}
response = requests.request("GET", url, data=payload, headers=headers)
答案 1 :(得分:0)
Zapier Platform团队的David在这里。
我没有处理Zapier在步骤之间序列化数据的方式,而是删除了上面的步骤2并将其折叠到JS代码步骤中。这样,整个代码将是:
// normally you'd need to wrap this in an `async` function, but Zapier does that for you
const res = await fetch('https://somesite.com/data');
const userRecords = await res.json();
return {isNotSubscribed: userRecords.find(o => o.categoryId === 'string 1')};