Help

Airtable Pagination Callback fetchNextPage

Topic Labels: API
Solved
Jump to Solution
4249 2
cancel
Showing results for 
Search instead for 
Did you mean: 
MQW
4 - Data Explorer
4 - Data Explorer

Hi, I am trying to build a SPA and having an issue with pagination.
From client side, it is calling back-end function to fetch image url of records and pageSize is 16.
What I am hoping to achieve is to fetch every 16 records whenever user clicks ‘show more photos’ and it will fetch another batch of 16 and so on…

but my question is how can I call fetchNextPage() after it fetches the first batch of records and function’s finished. I have little knowledge of callback function and how it works but if you could help me with this, I’d appreciate it.

Here is part of my cloud function

exports = module.exports = functions.https.onRequest(async (req, res) => {

const nextPage= (records, fetchNextPage)=>{
    fetchNextPage()
}
const processRecords = (err) => {
    console.log('done :>> ');
    if (err) {
      console.error(err)
      return
    }
}
_base(tableName).select({
    filterByFormula,
    fields,
    pageSize: 16

}).eachPage(processRecords, nextPage) 

});
1 Solution

Accepted Solutions
Matthew_Thomas
7 - App Architect
7 - App Architect

Welcome to the community @MQW!

What you’re looking for here is an offset value, so when the user clicks “Show more photos” a separate request is made to fetchNextPage() starting where the last request left off (e.g. photo #17 on the second request).

It looks like you’re using the Airtable.js framework for the back-end code based on the code I see, but it’s hard to tell without seeing more. Unfortunately, there’s nothing in the documentation about including offsets in the request using the framework. There is documentation on using it in a cURL request (found in the standard API docs for your base). A lot more detail/discussion can be found in this thread

with the tl;dr being you can add &offset=rec**** to the end of the URL to fetch records starting from that offset.

See Solution in Thread

2 Replies 2
Matthew_Thomas
7 - App Architect
7 - App Architect

Welcome to the community @MQW!

What you’re looking for here is an offset value, so when the user clicks “Show more photos” a separate request is made to fetchNextPage() starting where the last request left off (e.g. photo #17 on the second request).

It looks like you’re using the Airtable.js framework for the back-end code based on the code I see, but it’s hard to tell without seeing more. Unfortunately, there’s nothing in the documentation about including offsets in the request using the framework. There is documentation on using it in a cURL request (found in the standard API docs for your base). A lot more detail/discussion can be found in this thread

with the tl;dr being you can add &offset=rec**** to the end of the URL to fetch records starting from that offset.

MQW
4 - Data Explorer
4 - Data Explorer

Thank you Matthew for getting back to me. Yes I am using node.js for fetching data from AT. Haven’t thought about using curl and offset. Will try that and if still not work, will get back to the topic. Thank you