how to trigger webhook from zapier code

旧街凉风 提交于 2019-12-13 08:45:37

问题


I have 2 zaps. First finishes with Code by Zapier block, where I parse input information from previous steps getting array with data e.g.:

var elements = [{id: 12, calculatedValue: 13},{id: 13, calculatedValue: 'red'}]

then in a loop I traverse it, create requests bodies

var options = {
      "url": "https://hooks.zapier.com/hooks/catch/xxxxxx/xxxxxx/",
      "method": "POST"
    },
    requests = elements.map(mapDataToSettings);

function mapDataToSettings(elem) {
  var settings = Object.assign({}, options);
  settings.data = JSON.stringify(elem);
  return settings;
};

Then I'm doing HTTP calls with Fetch API for all those requests:

Promise.all(requests.map(grabContent))
.then(function(data){ callback(null, {requestsMade: data});});

function grabContent(options) {
  return fetch(options.url, options)
     .then(function(res) {return res.json();});
};

N.B. callback is function of Zapier to handle async results.

This code successfully runs and I can see results:

But those requests are not registered in webhook (address is correct. double checked.)

What may be the reason for this? How to fix my code to make requests activate webhook?


回答1:


It might be that you don't have a body item in your options that get sent with the fetch method. The documentation shows this as a POST example: { method: 'POST', body: 'a=1' }, so maybe try to make it exactly like that.



来源:https://stackoverflow.com/questions/46002614/how-to-trigger-webhook-from-zapier-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!