//native
type Airtable = {
apiKey: string;
};
type AirtableTable = {
baseId: string;
tableName: string;
};
export async function main(
atCon: Airtable,
atTable: AirtableTable,
recordList: object[],
) {
const url = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent(
atTable.tableName,
)}`;
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${atCon.apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
records: recordList.map((fields) => ({ fields })),
}),
});
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`);
}
const createMultiple = await response.json();
return createMultiple;
}
Submitted by hugo989 2 days ago