So I'm using jQuery Ajax to post using a bearer token that I'm having to get from someone's node.js app because I can't find Google docs on how to use your preferred language to get a bearer token for FCM use only. I'm using JSON.stringify
to prepare the payload data which someone shows on stackoverflow here. I've tried without but I just get a basic error message of Invalid_Arguments
. Using JSON.stringify
shows more to the error. It's stating that "to"
and "notification
" properties are unknown names but those are the property names used in Google docs. So what am I doing wrong?
Here's the link where someone says JSON.stringify
works. Before then I tried without JSON.stringify
which led to Invalid JSON Payload
and my reason for asking this question.
send post request to firebase cloud messaging by ajax?
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"to\": Cannot find field.\nInvalid JSON payload received. Unknown name \"notification\": Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"to\": Cannot find field."
},
{
"description": "Invalid JSON payload received. Unknown name \"notification\": Cannot find field."
}
]
}
]
}
}
$.post({
method: "POST",
url: "https://fcm.googleapis.com/v1/projects/floridarecycling-b91ec/messages:send",
dataType: "json",
contentType: "application/json",
headers: {
'Authorization': 'Bearer ' +
'ya29.c.ElqUBiCx...wyKqUqKlrg7yhPw'
},
data: JSON.stringify({
"to": "user_token",
"notification": {
"title": "Test",
"body": "test"
}
})
success: function () {
console.log("Success")
},
error: function (err) {
console.log("error ", err)
}
});`