本文介绍了如何从Zapier代码触发Webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个快章.首先以Code by Zapier块结束,在该块中,我解析先前步骤中的输入信息,以获取包含数据的数组,例如:

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;
};

然后我用Fetch API进行所有这些请求的HTTP调用:

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();});
};

NB callback是Zapier处理异步结果的功能.

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

此代码成功运行,我可以看到结果:

This code successfully runs and I can see results:

但是这些请求未在webhook中注册(地址正确.请仔细检查.)

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

这可能是什么原因?如何修复我的代码以使请求激活Webhook?

推荐答案

可能是您的options中没有通过fetch方法发送的body项目. 文档显示为POST示例:{ method: 'POST', body: 'a=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.

这篇关于如何从Zapier代码触发Webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-25 20:41