2017-08-29 44 views
0

我在Zapier代碼下面的代碼:這個響應對象是什麼意思? (Zapier JS代碼)

var settings = { 
    "url": "https://<HOST>/api/v1/siteinfo", 
    "method": "GET", 
    "crossDomain": true, 
    "headers": { 
    "authorization": "Basic <TOKEN>", 
    "cache-control": "no-cache" 
    } 
} 

fetch(settings.url, settings) 
    .then(function(res) { 
    return res.text(); 
    }) 
    .then(function(body) { 
    var output = {id: 1234}; 
    callback(null, output); 
    }) 
    .catch(function(error) { 
    callback(error.text()); 
}; 

我已經基本上從Zapier documentation複製。

運行此請求後,我得到這樣的迴應:

enter image description here

爲什麼有數據的大量的,一定的緩衝內容等,並不僅僅是簡單的{id: 1234}

回答

0

有此問題的兩個方面:

1.爲什麼沒有代碼工作?

目前 Zapier沒有告訴你的代碼更新將不會生效,除非你會告訴重新測試代碼由Zapier再弄運行JavaScript它可以在測試中找到的簡單方法Zap step這一步項目。

enter image description here

另一種方法是添加一些輸入參數。這也使Zapier重新評估代碼。

2.我得到的對象是什麼?

這是Fetch API定義的原始Response Object。需要用一些特定的方法解析它,如.text().json(),如Zapier的示例中所述,之後以的常規格式。