I’m having trouble with the Airtable API. I’m trying to fetch all records from a table, but the API is returning fewer records than what I can see in the Airtable UI.
Here’s my code:
const tableRecords = [];
function fetchRecords(base) {
base('Menu').select({}).eachPage(
function handlePage(records, getNextPage) {
tableRecords.push(...records);
getNextPage();
},
function handleDone(error) {
if (error) {
console.error('Error:', error);
return;
}
console.log('Fetched records:', tableRecords.length);
}
);
}
fetchRecords(airtable.base(baseId));
This code fetches 2202 records, but the UI shows 2271 records. Exporting to CSV also gives me 2271 records.
I’ve tried removing the view setting to make sure it’s not a display issue. I’ve also compared the API results with the CSV export and found the missing items, but I can’t figure out why they’re not being returned by the API.
Has anyone else run into this problem? Any ideas on how to fix it or what might be causing it?
I’ve dealt with this exact issue before, and it can be frustrating. In my experience, the problem often lies with how Airtable handles deleted records. When you delete a record in the UI, it might not immediately reflect in the API.
To solve this, I’ve found success in using the ‘filterByFormula’ parameter in the API call. Try something like this:
This ensures you’re only fetching non-deleted records. Also, double-check your base’s sync status - sometimes there’s a lag between UI changes and API availability.
If that doesn’t work, you might want to look into using a cursor-based pagination approach instead of offset-based. It’s a bit more complex to implement, but it can be more reliable for large datasets.
Remember, Airtable’s API has some quirks. Don’t hesitate to reach out to their support if you’ve tried everything and still can’t resolve the discrepancy.
hey man, i had a similar issue. make sure ur not using any filters or views in ur API call. also, check if u have any hidden fields in the UI that might not be coming thru the API. sometimes airtable can be weird with syncing too, so try waiting a bit and running ur code again. good luck!