Documentation

Airtable

Example Javascript code for importing data from Airtable

You can use Import Scripts to bring any data from your Airtable board directly into an Equals workbook.

Create an Airtable API Key and locate your Base ID

To find your API key, navigate to your account page. On your account overview page, under the API heading, there's a button that says "Generate API key." The base Id can be found in the URL of the API page of the base. In the URL, the base Id is immediately after https://airtable.com/ and starts with app. (You can also locate the base id by navigating to the Airtable Standard API page and clicking on the Airtable base that you want to use.)

Add the key to a secret group

Copy the the API key and base Id from the prior step. Then create a new secret group and paste the key into a new secret named airtable_api_key and airtable_base_id.

Example code

Once you've completed the prior steps, create a new workbook, add a new import script to a sheet and copy + paste the script below. Once pasted select your secret group in the toolbar (make sure the key in the secret group is called airtable_api_key and airtable_base_id).

You'll want to modify the code below to reflect the table name and titles of the columns in the table you're importing.

const equals = require("equals");
const axios = require("axios");

const AIRTABLE_BASE_ID = equals.getSecret("airtable_base_id");
const AIRTABLE_API_KEY = equals.getSecret("airtable_api_key");
const TABLE_NAME = "Contacts";

const getData = async () => {
  const resp = await axios({
    method: "get",
    url: `https://api.airtable.com/v0/${AIRTABLE_BASE_ID}/${TABLE_NAME}`,
    headers: {
      Authorization: `Bearer ${AIRTABLE_API_KEY}`
    }
  });
  return resp.data;
}

const data = await getData();

equals.addHeaders(["First Name", "Last Name", "Title", "Company", "Email"]);

for(const record of data.records) {
  equals.addRow([
    record.fields["First Name"],
    record.fields["Last Name"],
    record.fields["Title"],
    record.fields["Company"],
    record.fields["Email"]
  ]);
}