Help

maxRecords - clarification

Topic Labels: API
Solved
Jump to Solution
2010 6
cancel
Showing results for 
Search instead for 
Did you mean: 
Anthony7878
5 - Automation Enthusiast
5 - Automation Enthusiast

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?

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

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.

See Solution in Thread

6 Replies 6

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.

kuovonne
18 - Pluto
18 - Pluto

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.

Anthony7878
5 - Automation Enthusiast
5 - Automation Enthusiast

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