Back to APIs list

Airtable API examples & templates

Use these vals as a playground to view and fork Airtable API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// I was able to get this script to work from my browser console, but
// it's not working in ValTown or from Airtable's scripting environment.
// My best guess is that it has something to do with the headers not looking
// quite right to Substack when we hit their API.
const email = "hello.at.smallworld@gmail.com";
const body = {
additional_referring_pub_ids: "",
current_referrer: "",
current_url: "https://blog.edgeesmeralda.com/",
first_referrer: "",
first_url: "https://blog.edgeesmeralda.com/",
referral_code: "",
referring_pub_id: "",
source: "cover_page",
email,
};
const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
"headers": {
"content-type": "application/json",
"sec-ch-ua": "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"Referer": "https://blog.edgeesmeralda.com/",
"Referrer-Policy": "strict-origin-when-cross-origin",
},
"body": JSON.stringify(body),
"method": "POST",
});
console.log(await result.json());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// I was able to get this script to work from my browser console, but
// it's not working in ValTown or from Airtable's scripting environment.
// My best guess is that it has something to do with the headers not looking
// quite right to Substack when we hit their API.
const email = "hello.at.smallworld@gmail.com";
const body = {
additional_referring_pub_ids: "",
current_referrer: "",
current_url: "https://blog.edgeesmeralda.com/",
first_referrer: "",
first_url: "https://blog.edgeesmeralda.com/",
referral_code: "",
referring_pub_id: "",
source: "cover_page",
email,
};
const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
"headers": {
"content-type": "application/json",
"sec-ch-ua": "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"Referer": "https://blog.edgeesmeralda.com/",
"Referrer-Policy": "strict-origin-when-cross-origin",
},
"body": JSON.stringify(body),
"method": "POST",
});
console.log(await result.json());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// I was able to get this script to work from my browser console, but
// it's not working in ValTown or from Airtable's scripting environment.
// My best guess is that it has something to do with the headers not looking
// quite right to Substack when we hit their API.
const email = "avery.sara.james@gmail.com";
const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
"headers": {
"content-type": "application/json",
"sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
},
"referrer": "https://blog.edgeesmeralda.com/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body":
`{\"first_url\":\"https://blog.edgeesmeralda.com/\",\"first_referrer\":\"\",\"current_url\":\"https://blog.edgeesmeralda.com/\",\"current_referrer\":\"\",\"referral_code\":\"\",\"source\":\"home-sitemap\",\"referring_pub_id\":\"\",\"additional_referrin
"method": "POST",
"mode": "cors",
"credentials": "omit",
});
console.log(await result.text());
1
2
3
4
5
6
7
8
import { extractData } from "https://esm.town/v/andreterron/extractData";
import { saveToAirtable } from "https://esm.town/v/andreterron/saveToAirtable";
export async function receive_email(email: Email) {
console.log(JSON.stringify(email, null, 2));
const data = await extractData(email);
await saveToAirtable(data);
}
1
2
3
4
5
6
7
8
import { extractData } from "https://esm.town/v/andreterron/extractData";
import { saveToAirtable } from "https://esm.town/v/andreterron/saveToAirtable";
export async function receive_email(email: Email) {
console.log(JSON.stringify(email, null, 2));
const data = await extractData(email);
await saveToAirtable(data);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import process from "node:process";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export const airtable_get_sample = (async () => {
const data = await fetchJSON(
"https://api.airtable.com/v0/appXSrKDlwbAijRmD/All%20content/recxS2AKaE1klriwW",
{
headers: {
"Authorization": `Bearer ${process.env.airtable_pat}`,
},
},
);
// Sample data from: https://blog.airtable.com/database-vs-spreadsheet/
// appXSrKDlwbAijRmD is the name of the base, recxS2AKaE1klriwW is the record ID
return data;
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export async function GetPelotonWorkoutsAndSaveToAirTable(
req: express.Request,
res: express.Response,
) {
let response = await fetch("https://api.onepeloton.com/auth/login", {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
credentials: "include",
body: JSON.stringify({
username_or_email: process.env.peloLogin,
password: process.env.peloPass,
}),
});
const session = await response.json();
let workoutResponse = await fetch(
`https://api.onepeloton.com/api/user/${session["user_id"]}/workouts`,
{
method: "GET",
mode: "no-cors",
credentials: "include",
headers: {
"Content-Type": "application/json",
cookie: `peloton_session_id=${session["session_id"]};`,
"peloton-platform": "web",
},
},
);
const workouts = await workoutResponse.json();
const { Airtable } = await import(
"https://deno.land/x/airtable@v1.1.1/mod.ts"
);
const airtable = new Airtable({
apiKey: process.env.airTablePelo,
baseId: process.env.airTableBase,
tableName: "Table 1",
});
let ids = new Array();
let errors = new Array();
for (const key in workouts) {
airtable.create(
{
"fields": {
Name: key["name"],
Id: key["id"],
metrics_type: key["metrics_type"],
start_time: key["start_time"],
status: key["status"],
title: key["title"],
total_work: ["total_work"],
},
},
{ typecast: true },
function (err, record) {
if (err) {
console.error(err);
errors.push(err);
res.send(errors);
}
console.log(record.getId());
ids.push(record.getId());
},
);
}
res.send(`Records added ids: ${ids}`);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import process from "node:process";
export const airtable_deno_sample = (async () => {
const { Airtable } = await import(
"https://deno.land/x/airtable@v1.1.1/mod.ts"
);
const airtable = new Airtable({
apiKey: process.env.airtable_pat,
baseId: "appXSrKDlwbAijRmD",
tableName: "All content",
});
// Sample data from: https://blog.airtable.com/database-vs-spreadsheet/
const results = await airtable.select();
return results;
})();
1
Next