Skip to content

Commit c0edeca

Browse files
committed
Airtable docs page
1 parent 7ac7d83 commit c0edeca

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: Airtable
3+
---
4+
5+
Use the Airtable integration to create, read, update, and delete records in your Airtable bases.
6+
7+
Coming soon: subscribing to changes in your Airtable bases using triggers.
8+
9+
<Snippet file="integration-getting-started.mdx" />
10+
11+
## Installation
12+
13+
To get started with the Airtable integration on Trigger.dev, you need to install the `@trigger.dev/airtable` package.
14+
You can do this using npm, pnpm, or yarn:
15+
16+
<CodeGroup>
17+
18+
```bash npm
19+
npm install @trigger.dev/airtable@latest
20+
```
21+
22+
```bash pnpm
23+
pnpm add @trigger.dev/airtable@latest
24+
```
25+
26+
```bash yarn
27+
yarn add @trigger.dev/airtable@latest
28+
```
29+
30+
</CodeGroup>
31+
32+
## Authentication
33+
34+
To use the Airtable API with Trigger.dev, you can either use OAuth or a Personal Access Token.
35+
36+
### OAuth
37+
38+
```ts
39+
import { Airtable } from "@trigger.dev/airtable";
40+
41+
//this will use OAuth
42+
const airtable = new Airtable({
43+
id: "airtable",
44+
});
45+
```
46+
47+
### Personal Access Token
48+
49+
You can create an Airtable Personal Access Token [here on their developer site](https://airtable.com/create/tokens).
50+
51+
```ts
52+
import { Airtable } from "@trigger.dev/airtable";
53+
54+
//this will use the passed in token (defined in your environment variables)
55+
const airtable = new Airtable({
56+
id: "airtable",
57+
token: process.env["AIRTABLE_TOKEN"],
58+
});
59+
```
60+
61+
## Usage
62+
63+
Include the Airtable integration in your Trigger.dev job.
64+
65+
You can optionally add the types for your Table – this gives you nice type inference and errors when writing your code.
66+
67+
```ts
68+
//this is the type definition for my Table
69+
type LaunchGoalsAndOkRs = {
70+
"Launch goals"?: string;
71+
DRI?: Collaborator;
72+
Team?: string;
73+
Status?: "On track" | "In progress" | "At risk";
74+
"Key results"?: Array<string>;
75+
"Features (from 💻 Features table)"?: Array<string>;
76+
"Status (from 💻 Features)": Array<
77+
"Live" | "Complete" | "In progress" | "Planning" | "In reviews"
78+
>;
79+
};
80+
81+
client.defineJob({
82+
id: "airtable-example-1",
83+
name: "Airtable Example 1: getRecords",
84+
version: "0.1.0",
85+
trigger: eventTrigger({
86+
name: "airtable.example",
87+
}),
88+
integrations: {
89+
//make sure to add the integration here
90+
airtable,
91+
},
92+
run: async (payload, io, ctx) => {
93+
//adding the type to table<YourTableType>("<your table name>") gives you nice type inference and errors
94+
//you can leave it out as well table("<your table name>")
95+
const table = io.airtable.base("<your base id>").table<LaunchGoalsAndOkRs>("<your table name>");
96+
97+
//gets multiple records from the table. Here we only get the Status fields (columns)
98+
const records = await table.getRecords("muliple records", { fields: ["Status"] });
99+
await io.logger.log(records[0].fields.Status ?? "no status");
100+
101+
//Get a single record
102+
const aRecord = await table.getRecord("single", records[0].id);
103+
104+
//create a new record
105+
const newRecords = await table.createRecords("create records", [
106+
{
107+
fields: { "Launch goals": "Created from Trigger.dev", Status: "In progress" },
108+
},
109+
]);
110+
111+
//update the record we just created
112+
const updatedRecords = await table.updateRecords(
113+
"update records",
114+
newRecords.map((record) => ({
115+
id: record.id,
116+
fields: { Status: "At risk" },
117+
}))
118+
);
119+
120+
//wait 5 seconds
121+
await io.wait("5 secs", 5);
122+
123+
//delete the record we just created + updated
124+
const deletedRecords = await table.deleteRecords(
125+
"delete records",
126+
updatedRecords.map((record) => record.id)
127+
);
128+
},
129+
});
130+
```
131+
132+
## Tasks
133+
134+
| Function Name | Description |
135+
| -------------------------- | --------------------------------------------------------------- |
136+
| `base.table.getRecords` | Gets multiple records for a table. You can filter |
137+
| `base.table.getRecord` | Gets a single record (using the id) for a table. |
138+
| `base.table.createRecords` | Create one or more records in a table. |
139+
| `base.table.updateRecords` | Update one or more records in a table. |
140+
| `base.table.deleteRecords` | Delete one or more records in a table (using ids). |
141+
| `runTask` | Do anything that's possible with the official Airtable Node SDK |

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
{
189189
"group": "Integrations",
190190
"pages": [
191+
"integrations/apis/airtable",
191192
{
192193
"group": "GitHub",
193194
"pages": [

0 commit comments

Comments
 (0)