Hi,
I am trying to insert many (insertMany) records with realm webhook and google sheet using google app script into MongoDB.
but unfortunately getting an error
Exception: Attribute: payload[0], provided with invalid value: {Vehicle__MAKE=Acura, Vehicle__YEAR=2003
Here is the Google app script code.
for (var i=headerRows; i<numRows; i++) {
var formData = {
Vehicle__YEAR: `${data[i][columns.Vehicle__YEAR]}`,
Vehicle__MAKE: `${data[i][columns.Vehicle__MAKE]}`,
}
batchrecords.push(formData);
if(i == 5)break;
}
Logger.log(batchrecords)
var options = {
'method' : 'post',
'payload' : batchrecords,
};
var insertID = UrlFetchApp.fetch('https://us-east-3.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/googlesheet-xyisa/service/expoor/incoming_webhook/insert', options);
Here is the MongoDb Realm Sttich webhook code.
exports = async function(payload) {
const mongodb = context.services.get("mongodb-atlas");
const eventsdb = mongodb.db("Test");
const eventscoll = eventsdb.collection("cars");
const result= await eventscoll.insertMany(payload.query);
if(result) {
return { text: `Inserted` };
}
return { text: `Error saving` };
}
Here is the screenshot of logged data in the app script.
getting error
Exception: Attribute: payload[0], provided with invalid value: {Vehicle__MAKE=Acura, Vehicle__YEAR=2003
Can anyone help me in this regard?
Thanks