Reputation: 81
I am having trouble getting a Webhook to post from Zapier's Javascript code step. I need to use a Code Step because I want to send variable information to the same Webhook. I believe I have found a way to send the data I want to the Webhook.
fetch('https://hooks.zapier.com/hooks/catch/974762/krbqch/', { method:
'POST', body: 'a=1, another: textfield'})
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
}).then(function() {
callback();
})
.catch(callback);
I am getting an error that states "Error: You must return a single object or array of objects." This seems like this is something simple that I am not doing. I am just not sure what it is. Hoping I can get some help.
Upvotes: 2
Views: 1134
Reputation: 5262
David here, from the Zapier Platform team.
Your big issue is that you're calling the callback
function without any params. You want to either pass nothing (callback(null, {})
) or call it with some data (callback(null, {response: json})
).
Either way, it's important that the first parameter be null
if the function should exit successfully. Past that, I'd look at your body
. Right now you're setting values two different ways (=
and :
), which feels like it won't do what you expect.
All that said, you can still use variable data in Webhook steps (easier to configure than code) by mapping in values from previous steps. That might be an easier way to go about it.
Let me know if you've got any other questions!
Upvotes: 2