Netzo Logo

airtable

Airtable is a low-code platform for building collaborative apps.

Usage

import { airtable } from 'netzo/apis/airtable.ts'

const api = airtable({
  personalAccessToken: Deno.env.get('AIRTABLE_PERSONAL_ACCESS_TOKEN')
})

Configuration

The airtable factory function expects an object with the following, and returns an object with an API client api.

ParamTypeDefaultDescription
personalAccessTokenstringDeno.env.get('AIRTABLE_PERSONAL_ACCESS_TOKEN')the access token to use for authentication
Refer to official API documentation for more information.

Examples

The following examples assume you have created an api client instance.

Find records

Find all records that match the query.

const query: QueryRecords = {}
const result = await api[DATABASE_ID][TABLE_ID_OR_NAME].get<Records>(query)
const resultData = result.records

Add records

Add one or multiple records.

const data: DataRecords = {
  records: [
    {
      fields: {
        Address: '333 Post St',
        Name: 'Union Square',
        Visited: true
      }
    }
  ]
}
const result = await api[DATABASE_ID][TABLE_ID_OR_NAME].post<Records>(data)
const resultData = result.records

Update records

Update one or multiple records by id.

Id property of the data is optional if upsert property is enabled.

const data: DataUpdateRecords = {
  records: [
    {
      fields: {
        Address: 'Updated Address',
      },
      id: RECORD_ID
    }
  ]
}
const result = await api[DATABASE_ID][TABLE_ID_OR_NAME].patch<UpdateRecordsResult>(data)
const resultData = result.records

Delete records

Delete one or multiple records by id.

const query: QueryDeleteRecords = {
  records: [RECORD_ID_1, RECORD_ID_2]
}
const result = await api[DATABASE_ID][TABLE_ID_OR_NAME].delete<RecordsDeleted>(query)
const resultData = result.records

Find databases

Find all databases the api key can access.

const query: QueryDatabases = {}
const result = await api.meta.bases.get<Databases>(query)
const resultData = result.bases

Find tables

Find all tables in a specific database.

const query: QueryTables = {}
const result = await api.meta.bases[DATABASE_ID].tables.get<Tables>(query)
const resultData = result.tables

References