XMLHttpRequest Error when connecting to Airtable API in CodeSandbox

I’m trying to connect to Airtable using their official API in my CodeSandbox project but keep running into issues. I took the basic code from their documentation and modified it for my needs:

const Airtable = require('airtable');
const database = new Airtable({apiKey: 'MY_SECRET_KEY'}).base('DATABASE_ID');

database('Users').find('REC123456', function(error, data) {
    if (error) { console.error(error); return; }
    console.log('Found record:', data.id);
});

But every time I run this code, I get the same error message:

Error: Internal XMLHttpRequest Error

This is really frustrating because the code looks correct to me. Has anyone else encountered this problem when working with Airtable in CodeSandbox? What could be causing this XMLHttpRequest issue?

That XMLHttpRequest error happens when you’re using the Node.js Airtable library in a browser. CodeSandbox runs in browsers, so you need a different approach.

I hit this exact issue on a project last year. Skip the official Airtable npm package and just use fetch directly:

const apiKey = 'YOUR_API_KEY';
const baseId = 'YOUR_BASE_ID';
const recordId = 'REC123456';

fetch(`https://api.airtable.com/v0/${baseId}/Users/${recordId}`, {
  headers: {
    'Authorization': `Bearer ${apiKey}`
  }
})
.then(response => response.json())
.then(data => console.log('Found record:', data.id))
.catch(error => console.error(error));

This works great in CodeSandbox since fetch is built into browsers. The official package expects a server environment where XMLHttpRequest works differently.

i had a similar issue. sometimes codeSandbox messes up with CORS when using airtable. try switching to another browser or clearing ur cache. it helped for me!

That XMLHttpRequest error is super common with Airtable in CodeSandbox - ran into the exact same thing about six months ago on a client project. The official Airtable library is built for Node.js servers, not browsers, which is why you’re hitting this wall. I switched to using fetch with proper auth headers and it worked perfectly. CodeSandbox runs everything in a sandboxed browser with different security rules than a Node server. Double-check your API key has read permissions for that table, and definitely use CodeSandbox’s environment variables instead of hardcoding your credentials.

That XMLHttpRequest error happens because CodeSandbox’s browser environment doesn’t play nice with the Airtable SDK’s internal requests. I ran into this exact issue building a dashboard prototype last month. Skip debugging the SDK - just use axios or fetch with proper error handling instead. Double-check your API key has the right permissions for your base. Also make sure your CodeSandbox template allows client-side requests - some templates block external API calls. One more thing: verify you’re using the correct base ID format. Don’t just copy from the Airtable URL since that sometimes gives you the wrong identifier. Your base ID should start with ‘app’ plus alphanumeric characters.

First, double-check that your API key is valid - invalid keys can throw strange XMLHttpRequest errors. Also, CodeSandbox might be blocking the request depending on your project settings.