i have created a script to push new kids from one system into Airtable, i have been able to create the payload and a function to push the payload to Airtable API, it works, however it creates duplicate entries as well. I have double-checked the payload and i don't see any duplicates.
This is the script that finds the users to create
for (let user1 of modStuArray) {
if (user1.status === 'enrolled' || user1.status === 'admitted') {
const foundUser = !atToCompare.find(user2 => user2.oa_id === user1.oa_id);
if (foundUser) {
newUsers.records.push({
fields: {
...user1
},
});
}
}
postAt('app38098wehf','Students',newUsers)
}
This is the function to post payload into AT
function postAt (baseId, tableName, payload){
var options =
{
method: 'POST',
headers: {
'Authorization' : 'Bearer ' + atToken,
'Content-Type' : 'application/json',
"Accept": "application/json"
},
payload : JSON.stringify(payload),
//muteHttpExceptions : true,
//followRedirects: true
};
var response = UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseId + "/" + encodeURIComponent(tableName),
options).getContentText();
return(response);
}