I am using the Airtable js package for nodejs and it is my first time. I have dynamic data that I would like to store in a table. Is there a way to send the request once by passing an array into the create method? I don't want to iterate the array and call the create method on each iteration. I'm sure there is a way to do it once, I must be missing something.
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)=>{
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}`,
"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);
});
I do get this error response:
Error creating record: AirtableError {
error: 'INVALID_REQUEST_MISSING_FIELDS',
message: 'Could not find field "fields" in the request body',
statusCode: 422
}