0

I am trying to send Push Notifications (using Firebase platform) to my Android app through PostMan Chrome App, but I fail to make it work. I have followed all the instructions on connecting it, but it doesn't work. I can see that this is not an unusual problem, and therefore I have checked this, this, this and many more. Some console layouts/settings have changed and it's not that easy to follow ad literam, but I can see that the Authorization key is the secret.

However, even with all the check-ups and changes I have this: enter image description here

When I'm pressing on SEND to my app, it gives Unauthorized and Error 401. It is obvious what the problem is, but I don't know how to solve it. The Authorization key is the same both in the Firebase console and in the *.JSON file, while the body contains this:

{
  "to": 
    "/topics/NEWS"
  ,
  "data": {
    "extra_information": "This is some extra information"
  },
  "notification": {
    "title": "NEW NOTIFICATION!",
    "text": "Click me to open an Activity!",
    "click_action": "SOMEACTIVITY"
  }
}

I even tried to add the key after to:

And extract from the JSON file can be seen below: enter image description here Nothing worked. Can anyone help me with this, please? Do I need to use some other code from the JSON file? Help?

CuriousPaul
  • 449
  • 8
  • 20
  • Are you not on a network with a proxy requiring authentication? That could cause that error too – ernest_k Jan 22 '18 at 21:01
  • Interesting point, but I am not. Will try maybe to disable Firewall – CuriousPaul Jan 22 '18 at 21:02
  • Didn't work with disabling the Firewall – CuriousPaul Jan 22 '18 at 21:04
  • I’ve not seen `key=*` in an Auth header before. That doesn’t look right to me. Should it be something like `Bearer` then the key’s value? – Danny Dainton Jan 22 '18 at 21:29
  • Hmm. I will try with Bearer. I saw this in many tutorials, including this one: https://www.youtube.com/watch?v=heJmdX_djHs – CuriousPaul Jan 22 '18 at 21:31
  • With bearer, I get this *The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.* – CuriousPaul Jan 22 '18 at 21:34

1 Answers1

1

The key specified in the authorization header must be the Server key or Legacy Server key shown in the Firebase console tab for Project Settings > Cloud Messaging. The Web API key shown on the Project Settings > General tab will not work.

Also, the property for the notification text is body, not text:

{
  "to": 
    "/topics/NEWS"
  ,
  "data": {
    "extra_information": "This is some extra information"
  },
  "notification": {
    "title": "NEW NOTIFICATION!",
    "body": "Click me to open an Activity!", // <= CHANGED
    "click_action": "SOMEACTIVITY"
  }
}
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • Thank you, Bob. I just tried it, but nothing changed. I guess it's the Authentication method that creates these problems. – CuriousPaul Jan 22 '18 at 21:06
  • By the way, thank you for pointing this out. I had body in my code and text on Postman so I corrected it now. – CuriousPaul Jan 22 '18 at 21:08
  • For the value of the authorization key in the header, are you using the _Server key_ shown on the Project Settings/Cloud-Messaging tab of the Firebase console? I think either _Server key_ or _Legacy server key_ should work. – Bob Snyder Jan 22 '18 at 21:16
  • I have tried with both. I tried initially with the one in google-services.json (the one in the OP) and the one from Firebase > Project Settings > General where I also have the ID. The keys are, however, different. Should they be the same? – CuriousPaul Jan 22 '18 at 21:20
  • I don't know if this is relevant, but in the first option (Authorization) in PostMan I have None. `Authorization Type: None`. I only have that key in the header – CuriousPaul Jan 22 '18 at 21:22
  • I just tried using Postman with your message body and a test project of mine. The _Web API Key_ from the General Settings tab produced a 401 error. Both the _Server_ and _Legacy Server_ keys from the Cloud Messaging tab worked. – Bob Snyder Jan 22 '18 at 21:40
  • Now I get it!!! I failed to see the Columns next to ”General” on Project Settings. It works like a charm. Can you please edit your answer by adding this so I can vote your answer? Thank you very much! – CuriousPaul Jan 22 '18 at 21:52