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);
More about “Fetch GET response handling” related questions