Getting {"message":"val.replace is not a function"} while batch inserting notification

Hi,
I have an App action that runs and send notifications based on certain condition. When I use instance.batchInsert(notificationsToBeSent).then(() => {//Some other code in there}) I am getting 400 error and the response says, {“message”:“val.replace is not a function”}. I have double checked my code and everything is working as expected. Maybe the object that I am sending to batch insert has an issue but I checked and everything looks good. My code does not have val.replace anywhere or “val” either.

The value of notificationsToBeSent that I am sending to batch insert is,
[
{
“data”: {
“navigate”: {
“action”: “screen”,
“page”: 408335,
“query”: “?event=29kuYUjlTiCGkasdznuz42e”,
“transition”: “none”
},
“title”: “Hello! Aren’t you coming?”,
“message”: “In 2HR, Event will start! Click to RSVP”
},
“pushNotification”: {
“payload”: {
“custom”: {
“customData”: {
“action”: “screen”,
“page”: 242515,
“transition”: “none”
}
},
“title”: “Hello! Aren’t you coming?”,
“body”: “In 2HR, the Event will start! Click to RSVP”
}
},
“status”: “published”,
“scope”: {
“Email”: {
“$nin”: [
someEmail@gmail.com”,
someOtherEmail@gmail.com”,
someEmail2@gmail.com”,
]
}
}
}
]

Hello, Umar and thank you for your question.
“$nin” operator is not supported for batchinsert. You can use “$in” operator instead. You would need to do one extra step inside the action which is to get the list of all users from specific data source and exclude users you don’t want to send notifications to.

let dsName = “Users”;
let columnNameWithEmail = ‘Email’;

Fliplet.DataSources.connectByName(dsName).then(function (connection) {
return connection.find({attributes: [columnNameWithEmail]}).then(function(users){
let allUniqueUsers = .uniq(.map(users, ‘data.’ + columnNameWithEmail));
let exceptionsArray = [‘someEmail@gmail.com’, ‘someOtherEmail@gmail.com’, ‘someEmail2@gmail.com’, ‘User’];
let finalArrayOfUsers = allUniqueUsers.filter((email) => {
return !exceptionsArray.includes(email);
});
});
});

Replace variables dsName and columnNameWithEmail with the corresponding names in your app. And let me know if you have any other questions, will be happy to help.

Thanks Yuliia, It worked. It would be great if the Fliplet team mention this in their documentation.