1

From here:

How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

Trying this:

curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>"  -X POST -d '{ "to": "/topics/foo-bar","data": { "message": "This is a Firebase Cloud Messaging Topic Message!"}}' https://fcm.googleapis.com/fcm/send

With my API key. I get the response:

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

What am I doing wrong, or is there a different way to send notifications from my server (I'd be doing POST requests from my server). Using curl from terminal.

Is there a difference between a Web API key and a server key? I'm currently using the web api key.

Community
  • 1
  • 1
shell
  • 1,647
  • 2
  • 17
  • 31

2 Answers2

2

There are multiple key for firebase it seems. The one I needed was found doing:

Settings -> Cloud Messaging -> Look at the bottom for Server key.

shell
  • 1,647
  • 2
  • 17
  • 31
  • Thanks. That worked. In my test today, I successfully used "Server key", as you pointed out. I also was able to use "Legacy server key". – albert c braun Apr 29 '17 at 00:15
0

Referring to the docs, the Server Key is the expected/required key to be used for FCM (and GCM):

A server key that authorizes your app server for access to Google services, including sending messages via Firebase Cloud Messaging

However, recently there is a new value visible in the Firebase Console, called the FCM token which is advised to be used moving forward, since support for Server Keys are being deprecated, although it is still usable. (see my answer here for more details)

For the difference of the Web API key and Server Key (and other keys that might be related), you can see my answer here.

Community
  • 1
  • 1
AL.
  • 33,241
  • 9
  • 119
  • 257