小编Lio*_*Elk的帖子

如何在“Zapier 的代码”中编写 fetch?

在 zapier 中,我使用了Code By Zapier的动作。它基于 node.js。我需要使用fetch来实现我的 CRM 的 REST-API。

这是我编写的代码,当我使用 VS Code(在 Zapier 之外)尝试它时运行良好:

// the code by zapier includes already the require('fetch')

var api_token = "..."; // my api
var deal_name = "Example"; // a string

fetch("https://api.pipedrive.com/v1/deals/find?term="+deal_name+"&api_token=" + api_token)
  .then(function(res) {
    return res.json();
  }).then(function(json) {
     var deal_id = json.data[0].id;
     console.log("deal_id="+deal_id);
  }).catch(function(error) {
     console.log("error");
  });

output = {id: 1, hello: "world"}; // must include output...
Run Code Online (Sandbox Code Playgroud)

我从 Zapier 得到的错误是:

如果您正在执行异步(使用 fetch 库),则需要使用回调!

请帮我解决它。

callback fetch node.js zapier

1
推荐指数
1
解决办法
4047
查看次数

标签 统计

callback ×1

fetch ×1

node.js ×1

zapier ×1