Firebase curl is "Unauthorized" with correct API key

2,487

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.

Share:
2,487
shell
Author by

shell

Updated on December 01, 2022

Comments

  • shell
    shell over 1 year

    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.

  • albert c braun
    albert c braun almost 7 years
    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".