Trouble inserting array data into Airtable using Node.js create method

Hey everyone,

I’m new to Airtable and I’m struggling to add a record to a table. The data I want to insert is an array of objects. It worked fine when I had just one object, but now I need to handle multiple entries dynamically.

Here’s what I’ve tried:

const myBase = new Airtable({ apiKey: 'my-secret-key' }).base('my-base-id');

const peopleData = [
  { name: 'John Doe', age: 30 },
  { name: 'Jane Smith', age: 25 }
];

const formattedData = peopleData.map(person => ({
  Name: person.name,
  Age: person.age
}));

myBase('People').create(formattedData)
  .then(() => console.log('Data added!'))
  .catch(err => console.error('Oops:', err));

But I’m getting this error:

Oops: AirtableError {
  error: 'INVALID_REQUEST_MISSING_FIELDS',
  message: 'Could not find field "fields" in the request body',
  statusCode: 422
}

What am I doing wrong? How can I properly insert multiple records at once? Any help would be awesome!

hey nate, i had similar issues. try wrapping ur formattedData in an object with a ‘fields’ key, like this:

const recordsToCreate = formattedData.map(data => ({ fields: data }));

myBase(‘People’).create(recordsToCreate)…

this should work for multiple records. lemme know if u need more help!

I encountered a similar issue when working with Airtable’s API. The problem stems from how Airtable expects the data structure for bulk inserts. To resolve this, you need to use the create method with an array of objects, each containing a fields property. Here’s a modified version of your code that should work:

const recordsToCreate = formattedData.map(data => ({ fields: data }));

myBase('People').create(recordsToCreate)
  .then(records => console.log(`Added ${records.length} records successfully`))
  .catch(err => console.error('Error:', err));

This approach properly formats each record for Airtable’s API expectations. It should allow you to insert multiple records in one API call, improving efficiency. Let me know if you run into any other issues with this method.

I’ve been through this exact scenario, Nate. The issue lies in how Airtable expects the data structure for multiple records. Here’s what worked for me:

Instead of passing the array directly, you need to use the createRecords method and structure each record properly. Try this approach:

myBase('People').createRecords(formattedData.map(record => ({
  fields: record
})))
  .then(records => {
    console.log('Added', records.length, 'records successfully');
  })
  .catch(err => {
    console.error('Error creating records:', err);
  });

This method allows you to insert multiple records in a single API call, which is more efficient. Each object in the array needs to have a ‘fields’ property containing the actual data. Give it a shot and let us know if it resolves your issue.