Reputation: 3
I'm having trouble with triggering multiple webhooks via Zapier like explained on Zapiers website Did anyone manage to use this functionality?
I'm trying to create "an array of properly formed JSON objects". To be able to select it as data source in the next step it needs to be a simple array (thats why I stringify the jsons inside the array).
Here is the json array I'm creating in Zapier Code trying to use to trigger two separate webhooks being triggered
var jsonArray = ['{"id":1,"data":111}','{"id":2,"data":222}'];
output = {jsonArrayOut: jsonArray};
Here is a screenshot of a custom webhook request in Zapier
No matter how I format the data I always get one request, not two.
Could anyone please tell me what am I missing?
Upvotes: 0
Views: 1048
Reputation: 5262
Cool, so what you described in this comment should totally be possible.
Your zap will be the following:
{id, data}
(see below)This takes advantage of an undocumented feature of code steps where if they return arrays, the zap branches and subsequent steps run multiple times. Note that there's no UI for this and it'll look confusing, but it will work.
Your JS code will be something like the following:
// parse email code
// get items and their quantities
// return object that looks like this
return [{id: 1, data: 123}, {id: 2, data: 456}]
In step 3 (however you're doing that), you'll be able to select id
and data
as mappable inputs. When you're setting the zap up, you'll only see 1
and 123
as options, but when the zap is on and runs for real, step 3 will get run for each array element returned in step 2.
Upvotes: 1
Reputation: 731
According to the docs:
You can send an array of properly formed JSON objects, and we will trigger the Zap once for each object in the array.
Application will be able to parse through the json and understand its structure. Making it as a string makes it to lose it.
So I'm guessing sending it as a string might not work. The Application won't be able to find the number of elements inside the string, it will consider entire string to be one element.
Try,
output = [{"id": 1, "data": 111},{"id": 2, "data": 222}];
Upvotes: 0