Back to APIs

Create, update or delete single or multiple records in your bases.

Using our official Airtable integration

Create any tasks possible with the Airtable API.

Use io.runTask() and the official SDK or fetch.

Airtable integration docs

Example code using Airtable

Below are some working code examples of how you can use Airtable with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Stripe } from "@trigger.dev/stripe";
3
import { Airtable } from "@trigger.dev/airtable";
4
5
const stripe = new Stripe({
6
id: "stripe",
7
apiKey: process.env.STRIPE_API_KEY!,
8
});
9
10
const airtable = new Airtable({
11
id: "airtable",
12
token: process.env.AIRTABLE_TOKEN!,
13
});
14
15
type Customers = {
16
stripe_customer_id?: string;
17
Sales?: string[];
18
};
19
20
type Sales = {
21
payment_intent_id: string;
22
amount: number;
23
currency: string;
24
Customers?: string[];
25
"stripe_customer_id (from Customers)": string;
26
};
27
28
client.defineJob({
29
id: "stripe-new-sale-update-airtable",
30
name: "On new Stripe sale update Airtable",
31
version: "1.0.0",
32
integrations: {
33
stripe,
34
airtable,
35
},
36
trigger: stripe.onPaymentIntentSucceeded(),
37
run: async (payload, io, ctx) => {
38
const customersTable = io.airtable
39
.base("<your base id>")
40
.table<Customers>("<your table name>");
41
42
const salesTable = io.airtable
43
.base("<your base id>")
44
.table<Sales>("<your table name>");
45
46
const {
47
id: payment_intent_id,
48
customer: stripe_customer_id,
49
amount,
50
currency,
51
} = payload;
52
53
// Use the filter formula to find a customer record with the given stripe_customer_id
54
const records = await customersTable.getRecords(
55
"Filter records by stripe_customer_id",
56
{
57
filterByFormula: `{stripe_customer_id} = "${stripe_customer_id}"`,
58
fields: ["stripe_customer_id"],
59
}
60
);
61
62
let customerRecordId;
63
if (records && records.length > 0) {
64
// There is an existing customer
65
customerRecordId = records[0].id;
66
} else {
67
const newCustomerRecord = await customersTable.createRecords(
68
"create new customer record",
69
[
70
{
71
fields: { stripe_customer_id: stripe_customer_id as string },
72
},
73
]
74
);
75
customerRecordId = newCustomerRecord[0].id;
76
}
77
78
// Add sale to the Sales table
79
const newSaleRecord = await salesTable.createRecords(
80
"create new sale record",
81
[
82
{
83
fields: {
84
payment_intent_id,
85
amount,
86
currency,
87
Customers: [customerRecordId], // Link to the customer record using its ID
88
},
89
},
90
]
91
);
92
},
93
});