Home:ALL Converter>Fetch GET response handling

Fetch GET response handling

Ask Time:2017-05-31T00:38:37         Author:Jeff Wohlschlegel

Json Formatter

I am having some issues with Code by Zapier JavaScript trying to fetch some information from an API. I have success using the Webhook GET zap for the same API, but not using JS.

The reason for writing code is because I am trying to fetch and then immediately do some filtering on the response before sending it to the next step. I am now stuck, due to what I believe is a nuance in the response from the API.

var url = '...';
var username = '...';
var password = '...';
var auth = new Buffer(username + ':' + password).toString('base64');
var options = {
  method: 'GET',
  headers: {'Content-type': 'application/json', 'Authorization': auth, 'Accept': 'application/json'}
};
fetch(url, options)
.then(function(res) {
    return res.json();
})
.then(function(json) {
    json = json.filter(value => value.Item1bID === '1434');
    callback(null, json);
})
.catch(callback);

Author:Jeff Wohlschlegel,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44267638/fetch-get-response-handling
yy