Automatically fetch all pages?

Topic Labels: API
6827 4
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

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

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

}, function done(error) {
	if (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?

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.


4 - Data Explorer
4 - Data Explorer

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?