4

My application developed in NativeScript. For FCM I use nativescript-plugin-firebase.

I have received a push notification whenever I tried from the FCM console. But, I never received a push notification when I try from post man as below.

URL : POST : https://fcm.googleapis.com/fcm/send
Headers : Authorization = key="******", Content-Type=application/json

Data :

{
    "data": {
        "title": "RAJA RAJA",
        "message": "another test",
        "name": "Muthukumar ME"
    },
    "to" : "**************************************"
}

Response :

{
    "multicast_id": 5806593945960213086,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1521623661699559%161a06bff9fd7ecd"
        }
    ]
}

Anyone knows what have I missed that push notification is not coming when I try in postman even though I get a success response.

Michal
  • 15,429
  • 10
  • 73
  • 104
Muthukumar Marichamy
  • 1,175
  • 1
  • 17
  • 39
  • Have you followed [this](https://medium.com/android-school/test-fcm-notification-with-postman-f91ba08aacc3) tutorial? – Michal Mar 21 '18 at 09:35
  • Yes, I followed the tutorial. Still, I am not get any push notification even I got success response. – Muthukumar Marichamy Mar 21 '18 at 10:08
  • Have you tried adding the `notification` payload? As noted (here)[https://stackoverflow.com/questions/40809784/google-firebase-notifications-working-on-console-but-not-on-api?rq=1]. – Michal Mar 21 '18 at 10:53
  • 1
    Try sending a `notification` payload instead of `data`. When sending messages using the console, it is using a `notification` message payload (mentioned it [here](https://stackoverflow.com/a/41161456/4625829)). Possibly helpful post [here](https://stackoverflow.com/a/44621677/4625829). – AL. Mar 21 '18 at 10:58
  • Here I am explaining in details what payload is needed to send with this plugin and Postman https://github.com/NickIliev/TNSPushTest#push-notifications-with-postman – Nick Iliev Mar 21 '18 at 11:16
  • If you want to use data payload, you need to handle it manually – Paras Watts Mar 21 '18 at 11:57

4 Answers4

5
{ 
    "to" : "********",
    "priority": "high",
    "notification": {
        "title": "Title",
        "body" : "First Notification",
        "text": "Text"
    }
}
Michal
  • 15,429
  • 10
  • 73
  • 104
Muthukumar Marichamy
  • 1,175
  • 1
  • 17
  • 39
  • 1
    that's a "notification" notification, he's trying to send a "data" notification- this is not a correct answer - they work differently, and receiving one doesn't mean you'll receive the other, and arguably, data notifications are the ones you want – Saik Caskey May 11 '18 at 15:09
2

I am sending notification thru "topics" like:-

{
 "to" : "/topics/XXXX",

 "notification" : {
     "body" : "First Notification",
     "title": "Collapsing A",
     "click_action":"DisplayTestActivity"
 },
 "data" : {
     "body" : "First Notification",
     "title": "Collapsing A",
     "key_1" : "Data for key one",
   "click_action":"DisplayTestActivity"
 }
}

if you sending notification like this and you are unable to get the notification thru postman then

"Make sure that following line should be their in your splash activity or first page means executed before you are going to get notification "

FirebaseMessaging.Instance.SubscribeToTopic("XXXX");
if(!GetString(Resource.String.google_app_id).Equals("XXXXXXXXXXXXXXXXXXXXX"))  throw new System.Exception("Invalid Json file");
Task.Run(() =>
{

    var instanceId = FirebaseInstanceId.Instance;
    instanceId.DeleteInstanceId();
    Android.Util.Log.Debug("TAG", "{0} {1}", instanceId.Token, instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));

});

*above code is in c# so use your programming language.. thanks

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
0

Send Data Message using HTTP protocol with POSTMAN

You have to copy Legecy Server Key from Firebase Console > Project Settings > Cloud Messaging

Note: Firebase has upgraded our server keys to a new version. You may continue to use your Legacy server key, but it is recommended that you upgrade to the newest version.

Select POST. Enter request URL as https://fcm.googleapis.com/fcm/send Add Headers Authorization: key= OR Authorization: key=and Content-Type: application/json.

Setting-up with POSTMAN Now Select Body > raw > JSON (application/json) and add following code:

{
 "to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "First Notification",
     "title": "Collapsing A"
 },
 "data" : {
     "body" : "First Notification",
     "title": "Collapsing A",
     "key_1" : "Data for key one",
     "key_2" : "Hellowww"
 }
}

You can push a Generic notification (with notification payload) or a Custom notifications (with notification and data payload) and hit Send.

{
 "to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",
 "collapse_key" : "type_a",
 "data" : {
     "body" : "First Notification",
     "title": "Collapsing A",
     "key_1" : "Data for key one",
     "key_2" : "Hellowww"
 }
}

Note that Custom notification will only trigger if there is only data (without notification) node in the payload. Hence, you’d need to move the body and title to data node.

Keep in Mind : Use registration_ids instead of to node if you want to send notification to multiple devices with corresponding firebase_instance_id's.

Cecil Paul
  • 595
  • 6
  • 27
0
  1. Open your application in mobile and connect it to PC
  2. Then after opening chrome and paste this chrome://inspect/#devices in Remote Target Hit Inspect: Demo1
  3. Then after you will see the registrationId under Device registered
  4. Copy this Id and paste it after "to":"registrationId" in POSTMAN: Demo2

Hope it helps!

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Vardan
  • 9
  • 4