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!
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:
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.