简体   繁体   English

Zapier重新格式化获取响应

[英]Zapier Reformatting a Get Fetch Response

I am having some issues with Zapier and fetching some information. 我在Zapier上遇到了一些问题,并获取了一些信息。

What I am trying to do is fetch a url, receive a json response and send the entire response back to the next step to do additional processing. 我想做的是获取一个URL,接收一个json响应,然后将整个响应发送回下一步以进行其他处理。

Zapier seems to be ignoring the callback or any other code I wrote and just sending a 'zapier formatted' response to the next step, but NOT in json format. Zapier似乎忽略了回调或我编写的任何其他代码,只是向下一步发送“ zapier格式化”响应,但不是json格式。 Below are code samples: 下面是代码示例:

Request to client 要求客户

var authHeaders = {
    'Authorization': 'Bearer xxxx',
    'Content-Type': 'application/json'
}
var options = {
  method: 'GET',
  headers: authHeaders
};

fetch('www.url.com', options)
  .then(function(res) {
    return res.json();
  })
  .then(function (json) {
    callback(null, json)
  })
  .catch(callback);

Zapier next step option in the dropdown: 下拉菜单中的Zapier下一步选项:

input.name === harry,bob,sally
input.color === red, blue, green

Response from client 客户回应

{
  cats: [
    {name: 'harry', color: 'red'},
    {name: 'bob, color: 'blue''},
    {name: 'sally', color: 'green'},
    {name: 'mary', color: 'green'},
    {name: 'george', color: 'green'}
  ]
} 

What I want in the next zapier step is the clients response and not the Zapier Interpretation so I can do normal looping and parsing of a json object. 在下一个zapier步骤中,我想要的是客户端响应,而不是Zapier解释,因此我可以对json对象进行常规循环和解析。

cats.filter(function(cat){
  return cat.color === 'green'
})

I want all the cats that are green to be returned to the next step. 我希望所有绿色的猫都返回到下一步。 How can I do this, if all the cat attributes are in different zapier fields? 如果所有cat属性都位于不同的zapier字段中,该怎么办?

Another thing I tried is to reformat the zapier next step response after I make the GET request but zapier doesn't listen to me. 我尝试的另一件事是在发出GET请求后重新格式化zapier下一步响应,但zapier不听我的话。

fetch('www.url.com', options)
  .then(function(res) {
    callback(null, {dog: 'yorkie'})
  })
  .catch(callback);

The above code should just send the object I am passing on, {dog: 'yorkie'} but it returns the same 'zapier formatted cat response'. 上面的代码应该只发送我正在传递的对象, {dog: 'yorkie'}但是它返回相同的“ zapier格式的cat响应”。

Furthermore, when I didn't follow the zapier callback format and just put in the fetch request, it too sent back the 'zapier formatted cat response' to the next step. 此外,当我不遵循zapier回调格式而仅放入fetch请求时,它也将“ zapier格式的cat响应”发送回下一步。

fetch('www.url.com', options)

You'll likely want to do all your filtering in the JS step and only emit the records you care about instead of emitting all the records and making new steps that filter them. 您可能希望在JS步骤中进行所有过滤,而只发出您关心的记录,而不是发出所有记录并进行新的过滤步骤。

fetch('www.url.com', options)
    .then(function(res) {
        return res.json();
    })
    .then(function (json) {
        json = json.filter(record => record.color === 'green');
        callback(null, json);
    })
    .catch(callback);

If we get objects with nested lists - it can be difficult to get them back into the raw JS object format in follow up steps - so your best bet is to return an object with no nested arrays. 如果我们得到带有嵌套列表的对象-在后续步骤中很难将它们恢复为原始JS对象格式-因此,最好的选择是返回没有嵌套数组的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM