I’m working on a script that transfers student data from our system to Airtable using their API. The data transfer works fine, but I’m getting duplicate entries created in Airtable even though my payload doesn’t contain any duplicates when I check it.
Here’s my code that identifies which students need to be added:
for (let student of studentList) {
if (student.enrollment_status === 'active' || student.enrollment_status === 'pending') {
const isNewStudent = !existingRecords.find(record => record.student_id === student.student_id);
if (isNewStudent) {
studentsToAdd.records.push({
fields: {
...student
},
});
}
}
sendToAirtable('appXYZ123','StudentData', studentsToAdd)
}
And here’s my function for sending data to Airtable:
function sendToAirtable(baseId, table, data) {
var requestOptions = {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiToken,
'Content-Type': 'application/json',
"Accept": "application/json"
},
payload: JSON.stringify(data)
};
var result = UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseId + "/" + encodeURIComponent(table), requestOptions).getContentText();
return result;
}
Any ideas why duplicates are still being created?