//native
type Airtable = {
apiKey: string;
};
type AirtableTable = {
baseId: string;
tableName: string;
};
export async function main(
atCon: Airtable,
atTable: AirtableTable,
newRecord: 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({ fields: newRecord }),
});
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`);
}
const createOne = await response.json();
return createOne;
}
Submitted by hugo989 4 days ago