Automatically fetch all pages?


#1

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,


JSON string only contains 100 rows when connected to Power BI Desktop
#2

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


#3

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


#4

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.


#5

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?