Testing the Airtable API with a personal access token
Airtable often ends up as a small team's back office: a content calendar, an inventory, a list of beta customers. The integrations that read and write it are usually a script someone wrote once. A short test collection keeps them honest, especially after someone renames a field in the UI.
Step 1: Token and environment
At airtable.com/create/tokens, create a token with data.records:read, data.records:write and, for the schema check below, schema.bases:read. Give it access to the test base only.
| Variable | Value |
|---|---|
atBase | https://api.airtable.com/v0 |
atToken | pat…, marked as secret |
baseId | app… (from the base's URL) |
tableId | tbl… |
Authorization: Bearer token with {{atToken}}.
Step 2: Check the schema
GET {{atBase}}/meta/bases/{{baseId}}/tablesconst table = pm.response.json().tables.find((t) => t.id === pm.environment.get('tableId'));
const fields = table.fields.map((f) => f.name);
pm.test('fields the integration needs exist', () => {
['Name', 'Email', 'Status'].forEach((name) => pm.expect(fields).to.include(name));
});This is the test that catches "someone renamed Email to E-mail" before your sync silently writes nothing.
Step 3: List and filter
GET {{atBase}}/{{baseId}}/{{tableId}}?pageSize=100&filterByFormula={Status}='Active'&fields[]=Name&fields[]=Emailconst body = pm.response.json();
pm.test('records returned', () => pm.expect(body.records).to.be.an('array'));
body.records.forEach((r) => pm.expect(r.fields.Email, r.id).to.match(/@/));
if (body.offset) pm.environment.set('offset', body.offset);Empty fields are left out of fields entirely, not returned as null. Code that reads record.fields.Phone must handle undefined. See null vs missing fields.
Step 4: Create and update in batches
POST {{atBase}}/{{baseId}}/{{tableId}}
Content-Type: application/json
{
"records": [
{"fields": {"Name": "API test A", "Email": "[email protected]", "Status": "Active"}},
{"fields": {"Name": "API test B", "Email": "[email protected]", "Status": "Active"}}
],
"typecast": true
}const created = pm.response.json().records;
pm.test('two records created', () => pm.expect(created).to.have.lengthOf(2));
pm.environment.set('recordIds', created.map((r) => r.id).join(','));More than 10 records in one request answers 422. typecast: true lets Airtable convert values, such as adding a new option to a single-select field. Leave it off when you want strict checks.
To upsert by a field, PATCH with "performUpsert": {"fieldsToMergeOn": ["Email"]} updates matching records and creates the rest.
Step 5: Rate limit and errors
Five requests per second per base. Over it, Airtable answers 429, and you have to wait 30 seconds before the next request succeeds. In a run, --delay 250 keeps you safely under.
| Status | error.type |
|---|---|
401 | AUTHENTICATION_REQUIRED |
403 | INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND: no access, or the base doesn't exist |
404 | NOT_FOUND |
422 | INVALID_REQUEST_UNKNOWN, UNKNOWN_FIELD_NAME, INVALID_VALUE_FOR_COLUMN |
429 | rate limited |
Delete the test records in a cleanup step: DELETE {{atBase}}/{{baseId}}/{{tableId}}?records[]=rec…&records[]=rec…, up to 10 at a time.