Skip to main content

This loops through all the records from a view or search and performs the following steps for each record.



It is intended to run after something else triggers it.



It returns all fields of the records as well (as long as you include them in your query), so that you can use them as ingredients in the following steps of the zap without having to do a separate lookup.



T



Here is the code where you can copy and paste it.



var settings = {

'method': 'GET',

'headers': {

"Authorization": "Bearer <API KEY HERE>",

},

};

fetch('http://api.airtable.com/v0/APP_NAME_HERE/TABLE_HERE/?QUERYS_GO_HERE', settings)

.then(function(res) {

return res.text();

})

.then(function(body) { // body is the raw return from the API call

body.toString();

console.log();

var jsonData = JSON.parse(body);

var length = jsonData.length;

var output = [];

for (let i = 0; i < jsonData.records.length; i++){ // This for loop processes each record and adds it to the array

output.push(jsonData.records[i].fields);

}

callback(null, output);

})

.catch(callback);

This is awesome. When I tried to replicate for a relevant use case, I found that I had to replace var length = jsonData.length with var = Objects.keys(body).length full example below. But seriously, this helped me so much!



var settings = {

'method': 'GET',

'headers': {

"Authorization": "Bearer YOUR_API_KEY",

},

};

fetch('https://api.airtable.com/v0/YOUR_APP_ID/YOUR_TABLE_ID/?view=YOUR_VIEW_NAME_(REPLACE_ANY_SPACES_WITH_%20)', settings)

.then(function(res) {

return res.text();

})

.then(function(body) {

body.toString();

console.log();

var jsonData = JSON.parse(body);

var length = Object.keys(body).length;

var output = [];

for (let i = 0; i < jsonData.records.length; i++){

output.push(jsonData.records[i].fields);

}

callback(null, output);

})

.catch(callback);

Reply