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