Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Automatically fetch all pages?

Topic Labels: API
5514 4
cancel
Showing results for 
Search instead for 
Did you mean: 

Apologies if this is an ignorant question, but I want my call to the API to fetch all pages automatically, without extra user action.
I started with the sample code

base('allocations').select({
// Selecting the first 3 records in Main View:
maxRecords: 3,
view: "Main 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(error) {
	if (error) {
		console.log(error);
	}
});

The code appears to call fetchNextPage() after each page of results, which i expect will then call page() again. This does not happen; the next page is not fetched. What am I missing?
Thanks,

4 Replies 4

Since you’re specifying maxRecords: 3 in the select call, this will only fetch the first 3 records. You can remove line 3 to fetch all the records in “Main View”.

Thanks! Easier than I thought. For some reason I thought maxRecords was required. Problem solved.

I frequently have to remind myself how maxRecords and pageSize play together.

maxRecords determines the total number of records you want to retrieve. And since you could potentially be retrieving thousands of records in a single request, pageSize splits the records into “pages” with a maximum of 100 records per page.

67bb220bc0b1719f5e06b0d4d4cb014c2eedcac6.png

Hey
I have done everything in my get request to get pageSize=100 and no maxRecords and when I run it in postman I get the offset key with a value. But in my javascript code I don’t get the key offset back from my fetch. Any ideas what I might be doing wrong?