Post data to Airtable with the Airtable API


How to post data to Airtable with the Airtable API: install the Chrome extension, click Build with Browser agent, tell the agent what you want, and follow its prompts. A working bot is built and tested in minutes.

Here is how the automation works. To post data to Airtable with the Airtable API, add a Write javascript step that sends your scraped rows to https://api.airtable.com/v0/<base ID>/<table name> with a personal access token. Each row becomes a new record in the table. The Airtable API creates up to 10 records per request, so larger lists go in batches of 10.

Author
Alex Barlow
Published

Build the Airtable records from a description


Describe it and click the button: the agent builds and tests the automation in your Chrome extension. You need an Airtable personal access token with the data.records:write scope and access to the base.

  1. Go to the page I give you
  2. Scrape the details I want from it
  3. Add each row as a new record in my Airtable table
Click to launch the Chrome extension. Not installed? You can create an account and try it free.Opens the Chrome extension. Free account to try.

Have your Base ID (on the Airtable API page and in the base's URL, like appFrf1jmiyIq5nuJ), the table's name as written on its tab, and the exact field names of the table; the script creates records only in fields that exist.

The video shows the agent building the Airtable record creator from the lines above, in a few minutes.

Build the Airtable records step by step


The steps the agent builds, as the Builder shows them: each step by its name, with the fields to set under it. Add them yourself in this order in the step-by-step builder, or open the agent's result there to adjust it.

  • 1.0 Go to page
    • URL: the page with the details
  • 2.0 Get data from bot's current page
    • Select: each field you want, one column per Airtable field
    • Max results: 1 for a single record, up to 10 for one request, more for batches
  • 3.0 Write javascript
    • Script: the Airtable script for that number of rows, with your Base ID, table name, personal access token and field names in it, and [scrape-data] inserted

Common questions about posting data to Airtable


Why are no records created in Airtable?

Usually a credential or a field name is wrong. Check the Base ID, table name and token in the script, and that every field name matches your Airtable table exactly. The run stops with Airtable's error message; the runtime browser's console shows it too. When a run fails, hand it to the agent and it repairs the step.

Why does the Airtable request fail with a CORS error?

The browser blocked the request from the page. Turn on Run in app on the Write javascript step, so the script runs in the axiom.ai desktop app rather than the browser window.

Can I post to Airtable without a personal access token?

Yes. The Write data to Airtable step writes the scraped rows as new records through the Airtable connection you grant once from Credentials and API key on the dashboard, with no token and no script. Its columns go to the table's fields in order, and the fields must be text. The Airtable integration page covers connecting and the step; use the script on this page when you need to name the fields or write to non-text fields.

What is the limit on records sent to Airtable at once?

Ten per request, which is the Airtable API's limit. The batch script below sends any number of rows in batches of ten.

What does the script that posts to Airtable look like?

One of the three scripts below, whichever matches the number of rows. In each one, put your Base ID, table name and personal access token in the first three lines, and change the field names (Customer Name and the rest) to match your table exactly. Each script returns the IDs of the new records, one per row, as [code-data].

A single Airtable record

const AirtableBaseId = '*******'; // Add base ID
const AirtableTableName = '************'; // Add table name
const AirtableAccessToken = '**********'; // Add personal access token
const AirtableUrl = `https://api.airtable.com/v0/${AirtableBaseId}/${encodeURIComponent(AirtableTableName)}`;

// One record: field names on the left, axiom.ai tokens on the right
const recordData = {
  fields: {
    "Customer Name": '[scrape-data?all&0]',
    "Email Address": '[scrape-data?all&1]',
    "Phone Number": '[scrape-data?all&2]',
    "Customer ID": '[scrape-data?all&3]'
  }
};

const response = await fetch(AirtableUrl, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${AirtableAccessToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(recordData)
});
const result = await response.json();
if (!response.ok) {
  throw new Error(`Airtable error ${response.status}: ${JSON.stringify(result)}`);
}

return [[result.id]]; // The new record's ID

Up to 10 Airtable records

const AirtableBaseId = '*******'; // Add base ID
const AirtableTableName = '************'; // Add table name
const AirtableAccessToken = '**********'; // Add personal access token
const AirtableUrl = `https://api.airtable.com/v0/${AirtableBaseId}/${encodeURIComponent(AirtableTableName)}`;

// Replace the token used in this variable
const axiomData = [scrape-data];

// One record per row: field names on the left, row columns on the right
const records = axiomData.map((row) => ({
  fields: {
    "Customer Name": row[0],
    "Email Address": row[1],
    "Phone Number": row[2],
    "Customer ID": row[3]
  }
}));

const response = await fetch(AirtableUrl, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${AirtableAccessToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ records })
});
const result = await response.json();
if (!response.ok) {
  throw new Error(`Airtable error ${response.status}: ${JSON.stringify(result)}`);
}

return result.records.map((record) => [record.id]); // One new record ID per row

More than 10 Airtable records in batches

const AirtableBaseId = '*******'; // Add base ID
const AirtableTableName = '************'; // Add table name
const AirtableAccessToken = '**********'; // Add personal access token
const AirtableUrl = `https://api.airtable.com/v0/${AirtableBaseId}/${encodeURIComponent(AirtableTableName)}`;

// Replace the token used in this variable
const axiomData = [scrape-data];

// One record per row: field names on the left, row columns on the right
const records = axiomData.map((row) => ({
  fields: {
    "Customer Name": row[0],
    "Email Address": row[1],
    "Phone Number": row[2],
    "Customer ID": row[3]
  }
}));

const createdIds = [];
for (let i = 0; i < records.length; i += 10) {
  const batch = records.slice(i, i + 10); // Up to 10 records per request
  const response = await fetch(AirtableUrl, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${AirtableAccessToken}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ records: batch })
  });
  const result = await response.json();
  if (!response.ok) {
    throw new Error(`Airtable error ${response.status} on batch ${i / 10 + 1}: ${JSON.stringify(result)}`);
  }
  result.records.forEach((record) => createdIds.push([record.id]));
}

return createdIds; // One new record ID per row

How do I create an Airtable personal access token?

On the personal access token page in the Airtable Developer Hub: create a new token, name it, give it the data.records:write scope, grant it access to the base you want to add records to, and copy it.

Airtable create access token

Can I post data to Airtable without code?

Yes. The Write data to Airtable step writes your data to a table with the Base ID and table name, no token or script. See scrape a list of pages from Airtable and write the results back.

Can I post data to Airtable on a schedule?

Yes. Save the automation and set a schedule; each run scrapes the page again and creates a record for every row it finds.

Can I send the data to Make or another app instead?

Yes. See post scraped data to Make, which sends it with one Trigger webhook step.

Where do I get help?

Get in touch with support, or ask in the axiom.ai community.

Related guides