Hello,
I'm a new to the AirTable API and trying to automate adding records with data from another API. I have this function:
async function updateCrewRecords(data: CrewDetailsType[]) {
const crewBase = new Airtable({ apiKey: AT_API_KEY }).base('appxxx')
const table = cewBase('tblxxx')
const records = data.map((crew) => ({
fields: {
CrewID: crew.CrewID,
CompanyID: crew.CompanyID,
IsActive: crew.IsActive,
Position: crew.Position,
},
}))
try {
// const response = await table.create(records, { typecast: true })
const response = await table.update(records, {
typecast: true,
performUpsert: true,
fieldsToMergeOn: ['CrewID'],
})
} catch (e: any) {
const errorMsg = `updateCrewRecords(): ${e.message}`
console.log(e.statusCode, errorMsg)
// throw error(e.statusCode, e.message)
}
}
The commented out table.create(records) works as expected, but the upsert doesn't. The error I'm getting is:
422 updateCrewRecords(): Invalid request: parameter validation failed. Check your request data.
I can't find any way to get any more specific information on what is going wrong.
Any help would be much appreciated!
Thanks,
Adam.