Hello, first of all, the Airtable API documentation is great. That said, closely following the example code, i’m trying to understand how I might do something functional with the retrieve method.
Here is the example I am given from the API docs for my table ‘Users’
base('Users').select({
// Selecting the first 3 records in Grid view:
maxRecords: 3,
view: "Grid view"
}).eachPage(function page(records, fetchNextPage) {
// This function (`page`) will get called for each page of records.
records.forEach(function(record) {
console.log('Retrieved', record.get('ID'));
});
// To fetch the next page of records, call `fetchNextPage`.
// If there are more records, `page` will get called again.
// If there are no more records, `done` will get called.
fetchNextPage();
}, function done(err) {
if (err) { console.error(err); return; }
});
What i’d like to do is wrap this example up in a function and return an array of all records. But I don’t see how I might do that from the current documentation.
But additionally, having explored the source code, I’m wondering whether there is something missing?
In the firstPage()
and all()
functions, I notice the done()
function has two signatures: error case: done(err, null)
and success case: done(null, allRecords)
. But in the eachPage
function in the success case, the records are not passed on, it’s simply done(null)
.
I do have limited experience with javascript and node.js though so maybe this all fine. But seeing as there are one or two other threads on this forum of people having a similar issue, it might be at least worth giving a few more examples in the Airtable API documentation on how I might retrieve all records using the eachPage
function.
Thanks for any help and clarity you might be able to provide.
Thanks,
Oliver