Airtable API Get all records

Hello,

I am trying to pull data from Airtable via their API. Airtable's API only allows 100 records at a time to be pull.

I have created a resource for Airtable:

Then I have put it in the code sections:

How it works is that offset will be key and its value will be the cursor. For example: itrkWH1Axo8Yo44za/recpI5C2p2wBJH5bi If offset does not exist, that means you have pulled all the records from the table.

What I am trying to do is loop through the result and get all the from a table and stop when offset does not exist. I have tried multiple solutions that I have found on the forums and they are not working.

I would like to return an array on all the data.

Thank you in advance!

Hi @besteman - I think you would want to create another query of JavaScript type that would make multiple triggers of buyerLineItem until all records are fetched.

This JS query may look like this:

  let allRecords = [];
  let offset = null;

  while (true) {
    // I assume buyerLineItem query returns a portion of Airtable records
    const data = await buyerLineItem.trigger({
      additionalScope: {
        offset: offset || ''
      }
    })
    
    allRecords.push(...data.records);

    if (data.offset) {
      offset = data.offset;
    } else {
      break; // Exit the loop if there are no more records
    }
  }

  return allRecords;

Hope this helps!

I have tried something similar to this. When I do this, it never breaks out of the loop.

I would suggest to keep trying working on that script. I can confirm the script I provided works. It fetches 187 records which is more then 100 which is max per request

If you have budget I will be happy to help!

1 Like