Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't seem to pass an array into create method in Nodejs #409

Open
sparkmediatech opened this issue Jun 11, 2024 · 0 comments
Open

I can't seem to pass an array into create method in Nodejs #409

sparkmediatech opened this issue Jun 11, 2024 · 0 comments

Comments

@sparkmediatech
Copy link

sparkmediatech commented Jun 11, 2024

I have searched the entire internet if I could find a help but none. If this is possible, it is best added in the documentation. I just want to pass an array into the create method. I have dynamic data that I have stored inside an array variable. I don't want to use array iteration method to call the create method on each iteration as I think there should be an inbuilt method already existing to handle this. Maybe I am missing out on how to properly set it up.
If I make the data a single object, it goes through. Unfortunately, I have not been able to get array of objects to go through.

`

   export const createAirtable = (params: {participantData: participantDataAttributes[], orderDetails: AirtableOrderDetails, 
   orderedItemList: orderedItemListAttributes[]})=>{
   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({
        "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`
  })
})

console.log(tempRecord, 'record')
base(`${process.env.AIRTABLE_TABLEID}`).create(tempRecord as string[]).then(record => {
console.log('Created record');
}).catch(err => {
console.error('Error creating record:', err);
});
}

`

I get this error:
Error creating record: AirtableError { error: 'INVALID_REQUEST_MISSING_FIELDS', message: 'Could not find field "fields" in the request body', statusCode: 422 }
How is this done? And why are there limited contents on this package? I have been to stackoverflow, the community, google, Youtube, nothing could help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant