1 | |
2 |
|
3 | type Airtable = { |
4 | apiKey: string; |
5 | }; |
6 | type AirtableTable = { |
7 | baseId: string; |
8 | tableName: string; |
9 | }; |
10 | export async function main( |
11 | atCon: Airtable, |
12 | atTable: AirtableTable, |
13 | recordId: string, |
14 | newRecord: object, |
15 | ) { |
16 | const url = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent( |
17 | atTable.tableName, |
18 | )}/${recordId}`; |
19 |
|
20 | const response = await fetch(url, { |
21 | method: "PATCH", |
22 | headers: { |
23 | Authorization: `Bearer ${atCon.apiKey}`, |
24 | "Content-Type": "application/json", |
25 | }, |
26 | body: JSON.stringify({ fields: newRecord }), |
27 | }); |
28 |
|
29 | if (!response.ok) { |
30 | throw new Error(`${response.status} ${await response.text()}`); |
31 | } |
32 |
|
33 | const updateSingleRecord = await response.json(); |
34 |
|
35 | return updateSingleRecord; |
36 | } |
37 |
|