Reputation: 1056
//body its like this
{
"to":
"/topics/NEWS"
,
"data":{
"extra_information": "This is some extra information"
},
//notification that i need to give
"notification":{
"title": "ChitChat Group",
"text": "You may have new messages",
"click_action":"ChatActivity"
}
}
Upvotes: 59
Views: 55494
Reputation: 2924
Wrong:
Authorization:AIzaSyDDk77PRpvfhh......
Correct:
Authorization:key=AIzaSyDDk77PRpvfhh......
Full example:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
Upvotes: 23
Reputation: 13669
I was also getting same error in PHP , solved with below header :
$header = array("authorization: key=" . $this->apiKey . "","content-type: application/json");
Upvotes: 1
Reputation: 59
While the answers above are still correct, you may choose to use HTTP v1. This requires Bearer
instead of key=
and uses an Oauth2 access token instead of a server key string. To view HTTP v1 specifications, please refer to the link below:
https://firebase.google.com/docs/cloud-messaging/migrate-v1
Upvotes: 6
Reputation: 37778
The 401 error pertains that your Authorization Key is invalid or incorrect.
When using Postman, add a key=
prefix for the value of Authorization, like so:
key=AAA...
See below for a tutorial on Sending Downstream FCM Messages using Postman.
Also, for your notification
message payload, text
isn't one of the valid parameters, I think you were looking for message
instead.
Sending Downstream Messages using Postman
To do this in Postman, you simply have to set the following:
POST
Screenshots:
Note: Always keep your Server Key a secret. Only a portion of my key is visible here so it should be fine.
Notice that the request was a success with the message_id
in the response.
Upvotes: 145