API retrieval issue: Discrepancy in record count from Airtable

I’m having trouble with the Airtable API. My code fetches records, but the numbers don’t match up with what I see in the UI and CSV export.

Here’s a simplified version of my code:

const myBase = dataTable.base(baseIdentifier);

myBase('Menu')
  .select({})
  .eachPage(
    function handlePage(items, getNextPage) {
      allItems = allItems.concat(items);
      getNextPage();
    },
    function handleCompletion(error) {
      if (error) {
        console.log('Error:', error);
        return;
      }
      console.log('Finished. Total items:', allItems.length);
    }
  );

The API returns 2202 records, but the UI and CSV export show 2271. I’ve removed any view settings to confirm it’s not just a display issue.

I’ve compared the lists and found the missing items, but they don’t appear to have anything unusual. I understand which items are missing, but not why they’re missing.

Has anyone encountered this issue before? Any advice on resolving this?

hey liamj, when i encountered this issue, i found that some archived records weren’t accessible via the api. check if they’re hidden or if your key has restrictions. hope it helps!

I’ve run into this exact problem before, and it turned out to be related to record deletion. When you delete records in Airtable, they’re not immediately purged from the system. Instead, they enter a ‘soft delete’ state for a short period.

During this time, the UI and CSV exports might still show these records, but the API considers them gone. This can lead to the kind of discrepancy you’re seeing.

To verify if this is the case, try creating a new view in your base that only shows records created in the last 24 hours. Compare the count there with what the API returns for the same timeframe.

If that doesn’t explain it, check your API version. Older versions might have quirks that newer ones have resolved. Updating to the latest version could potentially fix the issue.

Lastly, if all else fails, try creating a new API key. Sometimes, permissions can get wonky, and a fresh key solves unexpected problems.

I’ve encountered a similar discrepancy before. In my experience, it was related to record caching. The API might not immediately reflect recent changes made in the UI. Have you tried waiting a bit and then re-running your API call? Sometimes it takes a few minutes for everything to sync up.

Another possibility is that your API key doesn’t have full access to all records. Double-check your API key permissions to ensure it has read access to the entire table.

If neither of these solve the issue, you might want to look into any filters or views you have set up. Even if you’ve removed them, hidden filters could still affect the API results.

Lastly, consider reaching out to Airtable support as they can offer insights into these kinds of discrepancies.