Reputation: 13
Using the Zapier UI to set up a zap.
Updated information about the zap flow as requested:
I have a GET that returns an array of objects, then I want to find if any of the objects have an ID that matches my target category ID string. If I choose the inputData.categoryId I can't get the entire array. I need to take action if the category ID is NOT in the array. Is there a way I can pass the entire payload of the GET into my next code action step?
I've tried passing in inputData.cateogryId but it runs the code step multiple times for each object in the array.
I'd like to be able to do something like this where inputData is the payload of the GET
const userRecords = JSON.parse(inputData);
output = {isNotSubscribed: false};
isNotSubscribed = userRecords.find(o => o.categoryId === 'string 1');
the input Data is in an array and looks like
[
{
"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",
}
]
Upvotes: 1
Views: 591
Reputation: 5262
David here, from the Zapier Platform team.
Rather than deal with the way Zapier serializes data between steps, I'd remove step 2 above and fold it into the JS code step. That way, the whole code would be:
// 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')};
Upvotes: 1
Reputation: 11
Instead of using Zapier UI for your "GET", you should consider using Python code to do it. Postman can easily translate your request from the app to Python code.
If you do so, the output of your python "GET" will be an array of dic. It should looks like this :
url ="yoururl"
params= {"key":"value"}
payload = {"key":"value"}
headers = {"key":"value"}
response = requests.request("GET", url, data=payload, headers=headers)
Upvotes: 1