I am trying to use Airtable for the first time. I want to simply create a record into a table in Airtable. The record is an array of objects. When I had the data as an object, it went through. But it is a dynamic data and would be in array form, I have not been able to get this to work.
Here is the current code that I am using:
const base = new Airtable({
apiKey: `${process.env.AIRTABLE_ACCESS_TOKEN}`,
}).base(`${process.env.AIRTABLE_BASEID}`);
const tempOrderParticipantData = [
...(params?.participantData as participantDataAttributes[]),
];
const tempRecord: unknown[] = [];
tempOrderParticipantData?.forEach((item, index) => {
const getPackage = params?.orderedItemList?.find(
(m, mIndex) => item?.packageName === m?.orderedItemName,
);
tempRecord?.push({
"Full Name": `${item?.participantNameInfo?.participantFirstName} ${item?.participantNameInfo?.participantLastName}`,
"First Name": `${item?.participantNameInfo?.participantFirstName}`,
"Last Name": `${item?.participantNameInfo?.participantLastName}`,
Phone: `${item?.participantNameInfo?.participantPhoneNumber}`,
Email: `${item?.participantNameInfo?.participantEmail}`,
"Tour Name": `${params?.orderDetails?.tripName}`,
"Tour Start Date": `${dayjs(params?.orderDetails?.tripStartDate).format("MMM/DDD/YYYY")}`,
"Tour End Date": `${dayjs(params?.orderDetails?.tripEndDate).format("MMM/DDD/YYYY")}`,
Quantity: `${params?.participantData?.length}`,
"Tour Price": `${displayCurrency(getPackage?.orderItemPrice as string)}`,
"Payment Status": `Successful`,
});
});
base(`${process.env.AIRTABLE_TABLEID}`)
.create(tempRecord as string[])
.then((record) => {
console.log("Created record");
})
.catch((err) => {
console.error("Error creating record:", err);
});
This is the error messsage that comes up when I try to create a record:
Error creating record: AirtableError {
error: 'INVALID_REQUEST_MISSING_FIELDS',
message: 'Could not find field "fields" in the request body',
statusCode: 422
}