I'm trying to test FCM using Postman, but I always get the following error even the FCM token is there. I got the token in the Cloud Messaging tab: Firebase Cloud Messaging token.
<HTML>
<HEAD>
<TITLE>The request was missing an Authentification Key (FCM Token). Please, refer to section "Authentification" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>
Here is what I send.
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Cache-Control: no-cache
Postman-Token: 9109eb13-245f-0786-21a5-6207f5426b44
Content-Type:application/json
Authorization:key=AAAAfnYrKvU:APA91bFwgeM3zuFId6UDzvIHk9qZ3lKHnX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{ "data": { "message": "This is a Firebase Cloud Messaging Topic Message!", } }:
working code for me like this-
POST:- https://fcm.googleapis.com/fcm/send
Header-
Content-Type: application/json
Authorization:key=AAAATIOk_eI:APA91bHR-NRuK-cVTc0fsdQ-N4SOAzocN7ngomFzcV7GkeCCHb6PmCFl_7MXTEPbdw-r0MTU9UmSbyxaSxxxxxxxxx.....
Body-
{
"registration_ids": ["fBclzMXz1UQ:APA91bE268ddn8DNB95LcU2XyhjjOXE-8PJ1nZ8y0yf1-4UuUX0fFNuae9Acj5BLYZwJq72tnNUjcUax9ZvRxxxxxxxxxxxxxxxxx...."],
"notification": {
"title": "Hello",
"body": "This is test message."
}
}
This is a sample postman POST request to send notifications to devices by using tokens.
Type: POST
Url: https://fcm.googleapis.com/fcm/send
Headers
key: Content-Type,
value: application/json
key: Authorization,
value: key="This is the key in your FCM project console->Settings->Cloud Messaging->Server Key""
body: "mode": "raw"
{
"to": "Token/s received to mobile end",
"notification" : {
"body" : "message",
"content_available" : true,
"priority" : "high",
"title" : "title of the notification"
}
}
After spending some hours I found that in Postman you have to put the following in the Headers.
Key: Content-Type
Value: application/json
Key: Authorization
Value: key=AAAAfnYrKvU:APA91bFwgeM3zuFId6UDzvIHk9qZ3lKHnX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(Firebase Cloud Messaging token)
Then click Body and select Raw, here you add the json.
{
"data": {
"title": "new messages",
"score": "5x1",
"time": "15:10"
},
"to": "/topics/alldevices"
}
I also found that you cannot send to all devices by eliminating the "to": You will have to have your app subscribe to a topic. In my case I made my app subscribed to "alldevices".
Now I can send "to":"/topics/alldevices" and all apps will receive the notification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With