//native
type Airtable = {
apiKey: string;
};
type AirtableTable = {
baseId: string;
tableName: string;
};
export async function main(
atCon: Airtable,
atTable: AirtableTable,
recordId?: string,
) {
const baseUrl = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent(
atTable.tableName,
)}`;
if (recordId) {
const response = await fetch(`${baseUrl}/${recordId}`, {
method: "GET",
headers: {
Authorization: `Bearer ${atCon.apiKey}`,
},
});
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`);
}
const record = await response.json();
return { result: record };
} else {
const response = await fetch(baseUrl, {
method: "GET",
headers: {
Authorization: `Bearer ${atCon.apiKey}`,
},
});
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`);
}
const records = await response.json();
return { result: records };
}
}
Submitted by hugo989 10 days ago