Muthukumar Marichamy
Muthukumar Marichamy

Reputation: 1214

FCM - Push notification works only in console not in postman

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.

Upvotes: 4

Views: 4747

Answers (4)

Vardan
Vardan

Reputation: 9

  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!

Upvotes: 0

Kundan Kumar
Kundan Kumar

Reputation: 37

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

Upvotes: 2

Cecil Paul
Cecil Paul

Reputation: 643

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.

Upvotes: 0

Muthukumar Marichamy
Muthukumar Marichamy

Reputation: 1214

{ 
    "to" : "********",
    "priority": "high",
    "notification": {
        "title": "Title",
        "body" : "First Notification",
        "text": "Text"
    }
}

Upvotes: 5

Related Questions