有没有办法将上一步中从GET返回的数组传递到Zapier中的代码操作步骤?

时间:2019-09-02 02:35:35

标签: javascript arrays zapier

使用Zapier UI设置一个zap。


根据要求更新有关zap流的信息:

  1. 是捕获挂钩触发器,当用户在源应用程序中执行特定操作时将触发该触发器。
  2. 是对应用程序的GET API调用,用于获取用户订阅。对于每个用户,将返回一组订阅。
  3. 是我的问题步骤-我想搜索数组以检查是否有任何预订与特定目标字符串匹配。
  4. 有条件的进步。检查步骤3的结果。如果数组中有匹配项,则不执行任何操作,它们已被订阅。如果没有,则继续。
  5. 发送POST以使用户订阅目标订阅。

我有一个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",
  }
]

2 个答案:

答案 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')};