I am trying to send notifications from a node server. I am using this code (which I got from reading this post):
request({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type' : 'application/json',
'Authorization': 'key=MY_SERVER_KEY'
},
body: JSON.stringify(
{ data: {
message: "Something delicious"
},
to: "DEVICE TOKEN"
}
)
}, function(error, response, body) {
if (error) {
console.error(error)
}
else if (response.statusCode >= 400) {
console.error('HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage)
}
else {
console.log('Message sent')
}
})
It responds with Message sent
, but I never receive an notification on my developer phone.
It works just fine when I am sending directly from Notifications tab in Firebase console.
What could I be doing wrong here?