Mar 09, 2022 12:02 PM
Hello,
Given:
var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('app6wt6DBFn40vPRg');
base('Project List').select({
// Selecting the first 3 records in Master List:
maxRecords: 3,
view: "Master List"
}).eachPage(function page(records, fetchNextPage) {
// This function (`page`) will get called for each page of records.
records.forEach(function(record) {
//do stuff
});
fetchNextPage();
}, function done(err) {
if (err) { console.error(err); return; }
});
How can maxRecords be determined dynamically via an API call?
Is this the only way?
Solved! Go to Solution.
Mar 09, 2022 05:40 PM
Welcome to the Airtable community!
maxRecords
is supposed to be the maximum number of records that your app wants. It is optional, and if you want to eventually get all of the records in the table, you should leave it blank. You may need to do multiple calls to all the records.
There is no easy way to get only the total number of records in a table.
Mar 09, 2022 05:07 PM
No, there are many approaches, but few are practical. Using the API to do this is the brute-force approach. Despite the 3 record limitation, it requires requesting all pages to get to the end. Ideally an event handler that reports the current record count of a table is needed.
Mar 09, 2022 05:40 PM
Welcome to the Airtable community!
maxRecords
is supposed to be the maximum number of records that your app wants. It is optional, and if you want to eventually get all of the records in the table, you should leave it blank. You may need to do multiple calls to all the records.
There is no easy way to get only the total number of records in a table.
Mar 10, 2022 05:34 AM
@kuovonne and @Bill.French I appreciate the clarity. I’m brand new to Airtable so even if no definitive answer exists I wanted to make sure I wasn’t overlooking something obvious.
Mar 10, 2022 06:16 AM
I think the supposition of this code example was to forego getting all the records, but instead knowing how many pages there are. As such, the idea is that it should be fast work to get to the end of the pages and then acquire only the records from the final page thus making it possible to know that actual count - i.e.,
((page count x 100) + last page record count) = total record count
This may be practical but I’m unsure how performant it really is over a full brute-force reading of every record.
Mar 10, 2022 06:56 AM
It can be hard to know exactly what a poster’s end goal is. I think there was confusion about maxRecords
and pageSize
and the total number of records in the table, and I was trying to clarify the differences.
I’m glad we both replied, as it seems that both of our answers were helpful.
Mar 10, 2022 07:04 AM
Yeah, that was the issue. Thank you for clarifying.
I need to go through all the records because my script compiles a geojson document with the data from Airtable to send to mapbox.com for a map application. I just needed to be sure I was getting all the records as the Airtable record count increases and I didn’t want to hard code a record count.