What's the best way to retrieve all entries (over 100) from Airtable using Axios?

I’m working on a project where I need to pull all the data from my Airtable base. The problem is, I can only get 100 records at a time. I’ve tried using Axios to make the API call, but I’m stuck on how to fetch more than 100 records. Here’s what I’ve got so far:

function getTableData() {
  const baseId = 'your_base_id_here';
  const apiKey = 'your_api_key_here';
  const url = `https://api.airtable.com/v0/${baseId}/Your_Table_Name?view=Your_View_Name`;

  axios.get(url, {
    headers: { Authorization: `Bearer ${apiKey}` }
  })
  .then(response => {
    console.log(response.data.records);
    // Do something with the data
  })
  .catch(error => {
    console.error('Error fetching data:', error);
  });
}

This works fine for the first 100 records, but how can I modify it to get all the records? Is there a way to use pagination or some other method? Any help would be appreciated!

I’ve encountered this issue before, and there’s a simple solution using the ‘offset’ parameter. Here’s an efficient approach:

function fetchAllRecords(baseId, apiKey, tableName) {
let allRecords = ;
let offset = null;

const fetchPage = async () => {
const url = https://api.airtable.com/v0/${baseId}/${tableName}?${offset ? offset=${offset} : ''};
const response = await axios.get(url, {
headers: { Authorization: Bearer ${apiKey} }
});
allRecords = allRecords.concat(response.data.records);
offset = response.data.offset;
if (offset) await fetchPage();
};

return fetchPage().then(() => allRecords);
}

This recursive function handles pagination automatically, fetching all records regardless of the total count. It’s concise and effective for large datasets.

hey luna23, i’ve been there too! here’s a quick tip: use the offset parameter in ur API calls. it’s like a bookmark for where u left off. just keep callin the API with the new offset til u get all the data. it’s pretty simple once u get the hang of it. good luck with ur project!

As someone who’s dealt with this exact issue, I can share what worked for me. The key is to use Airtable’s offset parameter for pagination. Here’s how I modified my code:

async function getAllTableData() {
  const baseId = 'your_base_id_here';
  const apiKey = 'your_api_key_here';
  let allRecords = [];
  let offset = null;

  do {
    const url = `https://api.airtable.com/v0/${baseId}/Your_Table_Name?view=Your_View_Name${offset ? `&offset=${offset}` : ''}`;
    try {
      const response = await axios.get(url, {
        headers: { Authorization: `Bearer ${apiKey}` }
      });
      allRecords = [...allRecords, ...response.data.records];
      offset = response.data.offset;
    } catch (error) {
      console.error('Error fetching data:', error);
      break;
    }
  } while (offset);

  return allRecords;
}

This function uses a do-while loop to keep making requests until there’s no more offset. It’s been reliable for me, even with thousands of records. Just remember to handle rate limits if you’re dealing with a very large dataset.