194

Firebase allows us to send notification messages via our own application by making POST request.

This tutorial, gives to us instructions how to make this request. However, there is Authorization field in header where I must to place my own Server key.

Where I can get this Server key? There are no instructions for this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mr.D
  • 7,353
  • 13
  • 60
  • 119

10 Answers10

349

Solution:

  1. Click the Settings (Cog wheel) icon next to your project name at the top of the new Firebase Console, as per screenshot below: enter image description here
  2. Click Project settings.
  3. Click on the Cloud Messaging tab.
  4. The key is right under Server Key. enter image description here
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hey @Frank Van Puffelen, is it the same thing? If i want it for Push Notifications where it says **"Get Application Server Keys"**. I am refering this link: https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/#get_application_server_keys. – divy3993 Jun 14 '17 at 19:29
  • the key has a ... after it, which gives an impression that full key is not being shown here. Also it doesn't have a copy button like legacy server key. Can you kindly update your answer, so that users may know how to copy it. – Ramesh Pareek Jun 22 '17 at 14:00
  • 3
    There is currently a bug in the Firebase console that hides the Copy button in some browsers. A fix is in flight and should be released next week. In the meantime, left click on the Server key label and press Tab key as a workaround. See https://stackoverflow.com/questions/44676388/firebase-dashboard-cant-see-full-server-key#comment76341929_44676388 – Frank van Puffelen Jun 22 '17 at 14:11
  • hi, im trying to send notifcation to Both android and IOS from php, but the server is key is Different for both the apps, should i keep condition to take android's serverkey for android notifications and ios's key for ios messages? – ɹɐqʞɐ zoɹǝɟ Sep 23 '17 at 05:25
  • It's not a tab, but the key is still there under the `Project credentials` heading on a row labeled `Server key`. – Frank van Puffelen Apr 03 '19 at 15:44
  • Is it possible to get this using the command line? I don't see it anywhere in the API docs. – a2f0 Dec 23 '19 at 20:07
  • I can't even see the expected items, but instead I see Web Push Certificates. – Tiny Angel May 26 '20 at 20:54
  • 25
    It looks like they updated the UI recently, does anyone know where to find the Server Key in the new UI? – DanielRead Jun 02 '22 at 15:58
  • 5
    @DanielRead, please ref this link https://documentation.onesignal.com/docs/generate-a-google-server-api-key – Ashwin H Sep 08 '22 at 10:32
  • @AshwinH thank you, I'll add this link to my answer for others to see – DanielRead Sep 08 '22 at 13:14
61

Updated UI June 2022

I was able to get the Server key by doing the following steps:

  1. Click on the "..." next to "Cloud Messaging API (Legacy)"
  2. Click "Enable Cloud Messaging Api (Legacy)"
  3. Go back to the previous page and refresh and you should now see the Server Key

Not sure if we need to do something different moving forward now that it's considered legacy....

Steps with images: https://documentation.onesignal.com/docs/generate-a-google-server-api-key

DanielRead
  • 2,288
  • 1
  • 23
  • 34
  • 6
    For me, after clicking "..." I also needed to click on the pop-up button to go to Google Cloud Console and then enable Cloud Messaging API (Legacy) there. After that, I returned to the tab with Project Settings (Cloud Messaging), refreshed the page and the key was there under the Legacy API section. – OatMeal Jun 08 '22 at 22:16
19

July 2022

  1. Click on the "..." (Positioned vertically) next to "Cloud Messaging API (Legacy) (DISABLED)" on your Firebase project settings.
  2. Click on the pop-up menu listing. *It should say something like "Manage API in Google Cloud Console"

OnClick it will redirect to your google cloud console page, over there you should see an option to enable the Cloud Messaging API. Enable it and go back to your Firebase project settings and wallah, its there!

Kyoto
  • 308
  • 4
  • 4
14

Take this one: (First answer is right - this one is just to show how the page looks like!) https://support.clevertap.com/docs/android/find-your-fcm-sender-id-and-fcm-server-api-key.html#

enter image description here

Naeem Ibrahim
  • 3,375
  • 1
  • 21
  • 21
Mike Mitterer
  • 6,810
  • 4
  • 41
  • 62
  • hi, im trying to send notifcation to Both android and IOS from php, but the server is key is Different for both the apps, should i keep condition to take android's serverkey for android notifications and ios's key for ios messages? – ɹɐqʞɐ zoɹǝɟ Sep 23 '17 at 05:26
13

UPDATE: As of April 2017 this method does not work. The api_key in google-services.json is only the legacy key. The selected answer is correct.


Deprecated way:

In your project there is a JSON file called google-services.json

Open that file and search for

"api_key": [
        {
          "current_key": "********"
        }

those *** are your server api key

If you dont have that file then you can download it from your app details in firebase account

enter image description here

David Schumann
  • 13,380
  • 9
  • 75
  • 96
  • 2
    FYI, I just spent hours debugging push notification using "current_key" value. Not that I got this from your answer. Turns out you need to get the Servery Key the way the selected answer says. – Dhunju_likes_to_Learn Dec 16 '16 at 03:29
  • 1
    Maybe your answer was right in the past but now (Feb. 2017) it is wrong. The selected answer is right! – Mike Mitterer Feb 24 '17 at 11:53
9

Updated UI 2022

Here are Steps to get serverKey

  1. GO to firebase console

  2. You can get view like this. if you have Created Project select project else Create new Project by click on Add project. enter image description here

  3. Now you are in Project overview panel.

  4. In Project overview panel in left upper corner click on settings button and go to Project Settings --> Cloud Messaging

enter image description here

  1. That's it. in Project credentials Key and token are mentioned. Copy code and paste it. You are good to go enter image description here
KARNAV PARGI
  • 445
  • 1
  • 4
  • 15
8

There are two keys on firebase, the first one is in Settings (Tab General) and its call Web API Key.

The second one and in what you are interesting for is in Settings (Tab Cloud Messaging) its called Server key

Use the second one for push notifications from php.

Jonathan Guerrero
  • 341
  • 1
  • 4
  • 8
8

enable that in 5 step

Go to Firebase Console > Projects Settings > Cloud Messaging

enter image description here

click on Manage API in Google Cloud Console

Go to API Library using the back button as shown below.

enter image description here

In the search bar, type cloud messaging and select Cloud Messaging

enter image description here

Click Enable to start using the Cloud Messaging API

enter image description here

Now Come Back Projects Settings > Cloud Messaging

4

In my case, I did an integration with a 3rd party system and they asked for the "server key" json file.

They what I get it from firebase was: Project Overview -> Project Settings -> Service accounts screen and A press the Generate new private key button. I used that file and everything worked as expected

enter image description here

4

As of 2023, solution below works flawlessly:

  1. Go to this link and enable: "Cloud Messaging" service:

https://console.cloud.google.com/apis/api/googlecloudmessaging.googleapis.com

  1. Go back to Firebase Console > Projects Settings > Cloud Messaging

You will see that Cloud Messaging API (Legacy) is now enabled and you can see your Server key there. That is it.

firebase console project settings

KHAN
  • 537
  • 5
  • 12