Hi i working with Node JS and Firebase SDK,
Im trying to send FCM notificacion as documentation says: https://firebase.google.com/docs/cloud-messaging/admin/send-messages?hl=es-419,
My code:
function testMessage(){
let token="f8mNlJq4VOY:APA91bF5_8ldOZEm34ajCfNx7hZ9_LhjUBQFDwZbtSnCNEzb1bEtMsXKlM8upyicvmnJ92xELZzDSxTMaeZrCrrau"
let message={
notification: {
title: "Account Deposit",
body: "A deposit to your savings account has just cleared."
},
data: {
score: '850',
time: '2:45'
},
token:token
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
}
But when i execute, this show this error:
Error sending message: { Error: Request contains an invalid argument. at FirebaseMessagingError.FirebaseError [as constructor] (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:39:28) at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:85:28) at new FirebaseMessagingError (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:241:16) at Function.FirebaseMessagingError.fromServerError (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:271:16) at C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\messaging\messaging-api-request.js:149:50 at at process._tickCallback (internal/process/next_tick.js:188:7) errorInfo: { code: 'messaging/invalid-argument', message: 'Request contains an invalid argument.' }, codePrefix: 'messaging' }
The SDK its loading, and dependences are workin. Can you help me to fix it?