Help

Re: Airtable Pagination

539 0
cancel
Showing results for 
Search instead for 
Did you mean: 
BeUni_Tecnologi
5 - Automation Enthusiast
5 - Automation Enthusiast

I'm using the Airtable Node SDK and the type for `offset` is `number` but it throws an error of "INVALID_OFFSET_VALUE". Passing a `string` also throws an error "Error: Airtable: invalid parameters for `select`".

Also, I don't get the `offset` string from the response when using the SDK.

Is it possible to do pagination with the SDK? I see there's a function for `.select().eachPage()` but I'm not sure how to use it to implement pagination.

If requesting via Fetch, I get the `offset` string from the response and I'm able to send it to the next request and get the next page, but how do I navigate backwards? I would need to store in a hash map ( { 0: null, 1: 'first_page/offset_string', ... } ) ?

Another question is: Is it possible to implement a "normal" pagination? Like, navigate to an specific page, navigate backwards, etc.?

4 Replies 4
cassie2698bratt
4 - Data Explorer
4 - Data Explorer

@BeUni_Tecnologimary kay in touch wrote:

I'm using the Airtable Node SDK and the type for `offset` is `number` but it throws an error of "INVALID_OFFSET_VALUE". Passing a `string` also throws an error "Error: Airtable: invalid parameters for `select`".

Also, I don't get the `offset` string from the response when using the SDK.

Is it possible to do pagination with the SDK? I see there's a function for `.select().eachPage()` but I'm not sure how to use it to implement pagination.

If requesting via Fetch, I get the `offset` string from the response and I'm able to send it to the next request and get the next page, but how do I navigate backwards? I would need to store in a hash map ( { 0: null, 1: 'first_page/offset_string', ... } ) ?

Another question is: Is it possible to implement a "normal" pagination? Like, navigate to an specific page, navigate backwards, etc.?


Hello,

You're right, the Airtable Node SDK currently (as of June 2024) doesn't have built-in support for pagination using an offset value. Here's a breakdown of your questions and approaches:

1. INVALID_OFFSET_VALUE Error:

The offset parameter in .select() expects a number, not a string. Supplying a string will cause the "invalid parameters" error.
2. Pagination with .eachPage():

You're on the right track with .eachPage(). This function is designed for iterating through paginated Airtable responses.
Here's how to use it for pagination:

 

 

const base = airtable.base('yourBaseId');
const table = base('yourTableName');

const pageSize = 100; // Adjust as needed

table.select({
  pageSize
})
.eachPage(
  (records, fetchNextPage) => {
    // Process the current page of records (array)
    console.log(records);

    // Check if there's a next page
    if (fetchNextPage) {
      fetchNextPage(); // Fetch the next page
    }
  },
  (err) => {
    if (err) {
      console.error(err);
    }
  }
);

 

 

This code fetches pages of pageSize records and calls fetchNextPage when available.

Navigating Backwards:

Unfortunately, the SDK doesn't provide a direct way to navigate backwards. The .eachPage() approach iterates forward only.
If you need true backward navigation, consider storing the returned record IDs or another unique identifier in your application state and using them for specific record retrieval.
4. "Normal" Pagination:

The SDK doesn't currently offer functionality to navigate to a specific page number.
You can achieve a similar effect by adjusting the pageSize in .eachPage() to simulate page sizes. Keep track of the processed records and manually calculate the "page number" based on the retrieved records and pageSize.

I hope the information may help you. 

 

 

merryray
4 - Data Explorer
4 - Data Explorer

 

  • The Airtable Node SDK abstracts offset handling with its pagination methods like .eachPage().
  • Traditional pagination features like navigating to a specific page or backwards are not directly supported by Airtable's API; you'll need to manage this manually by storing fetched pages or offset values.
  • Implementing pagination with Airtable Node SDK involves iterating through pages using .eachPage() and managing navigation requirements (like going backwards) locally.

 

merryray
4 - Data Explorer
4 - Data Explorer

Thak You for the details. 

michellecarl
4 - Data Explorer
4 - Data Explorer

 

With its pagination methods, such as.eachPage(), the Airtable Node SDK abstracts offset management.
The API of Airtable does not explicitly support traditional pagination features, such as navigating to a specific page or reversing. Consequently, you will be required to manually manage this by storing fetched pages or offset values.
To implement pagination with the Airtable Node SDK, it is necessary to iterate through pages using.eachPage() and manage navigation requirements (such as reversing navigation) locally. MyKohlsCard Login