//native
type Airtable = {
apiKey: string;
};
type AirtableTable = {
baseId: string;
tableName: string;
};
export async function main(
atCon: Airtable,
atTable: AirtableTable,
recordId: string,
newRecord: object,
) {
const url = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent(
atTable.tableName,
)}/${recordId}`;
const response = await fetch(url, {
method: "PATCH",
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 updateSingleRecord = await response.json();
return updateSingleRecord;
}
Submitted by hugo989 6 days ago