Oct 28, 2016 12:00 PM
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,
Oct 28, 2016 12:04 PM
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”.
Oct 28, 2016 12:09 PM
Thanks! Easier than I thought. For some reason I thought maxRecords
was required. Problem solved.
Oct 30, 2016 11:26 AM
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.
Jun 18, 2018 09:35 AM
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?