maxRecords - clarification



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
}, function done(err) {
    if (err) { console.error(err); return; }

How can maxRecords be determined dynamically via an API call?

Is this the only way?

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.

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.

1 Like

@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.

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.

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.

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 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.

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.