An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions enter image description here
6 Answers
For solving this problem I took the following steps:
- open Google Cloud Platform Dashboard
- Go to API and Services
- Enable API and Services
- Search for Cloud Messaging
- Turn on the cloud messaging and Firebase cloud messaging API.

- 1,060
- 1
- 8
- 14
-
13This solved my issue. `Firebase cloud messaging` API was already enabled. I had to just enable the `cloud messaging` API. Thanks @Peshraw Hasan – kamasuPaul Jul 10 '22 at 04:19
-
1Worked for me too. Didn't know you had to enable regular google cloud messaging in addition to the Firebase Cloud Messaging. – Eric Jul 15 '22 at 06:47
-
2Thank you so much kamasuPaul. I am surprised that this is not stated in the doc. Even filter with cloud messaging will not show this option. You have to search for cloud messaging at the top, then enable it. After that everything works as expected. – function1983 Jul 19 '22 at 20:05
-
Worked for me, Just added Cloud Messaging in to the project. then it worked fine – Chinthaka Dinadasa Aug 25 '22 at 19:00
-
1Firebase should mention this in the Docs, thanks Peshraw!! – Zubeir Sep 21 '22 at 19:37
-
firebase cloud messaging already enable in my console still its shows this error. my code is as follows: `admin.messaging().sendToDevice(deviceToken, payload).then((resp) => { console.log('response in', resp); })`. and the device token i have given is the fcm token of the device – Akash Sep 22 '22 at 04:09
-
why google just activated firebase messaging rather than just enabling both – Clode Morales Pampanga III May 06 '23 at 01:04
By default Firebase uses Firebase Cloud Messaging API (V1) so you need to use this api instead of legacy one
for Firebase Cloud Messaging API (V1) :
const data = {
message: {
token: registrationToken,
notification: {
title: "Notification Title",
body: "Notification Body ",
},
data: {
Nick: "Mario",
Room: "PortugalVSDenmark",
},
},
};
admin.messaging().send(data.message);
for Cloud Messaging API (Legacy) 1.First go to Google Cloud Platform Dashboard and enable Cloud Messaging Service 2. and then you can use like this :
var payload = {
notification: {
title: "This is a Notification",
body: "This is the body of the notification message.",
},
};
var options = {
priority: "high",
};
var registrationToken ="your device token";
admin
.messaging()
.sendToDevice(registrationToken, payload, options)
.then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
Firebase Cloud Messaging API (V1) is recommended than Cloud Messaging API (Legacy)

- 1,826
- 2
- 8
- 11
-
This worked for me too. I think the interface has changed if you're using the newer API. – d512 Aug 28 '22 at 18:17
-
Thanks a lot. By 2023 API is FCM v1 by default. So following related API is the way to go as pointed by @Abhishek – Stéphane de Luca Feb 16 '23 at 12:18
I just came across this issue and, for me, it was because I was using a simulator. The FCM token generated by the simulator isn't valid for firebase cloud messaging and it was throwing this error.
I put my admin.messaging().sendToDevice()
into a try catch
and it's working fine.
I don't know if is sends the notification only to the valid tokens or if it totally ignores all of them though

- 1,233
- 17
- 37
-
1I was wondering how to get to the screen in the image. I finally figured it out following the doc in the [link](https://firebase.google.com/docs/admin/setup) – Dipen Feb 17 '22 at 16:36
-
In my case, following Abhimanyu's solution to generate a new key still couldn't solve the problem.
After digging for 5 hours, I found the root cause that Google didn't activate this API for my project!!!!
It works After I activate the Cloud Messaging permission.

- 135
- 1
- 4
-
-
But this is the legacy version, which firebase recommended to not use. – Junius L Sep 02 '23 at 09:42
Just to clarify the FCM v1 usage as pointed by @Abhishek Ghimire.
Here is how to create the message:
const message = {
token: registrationToken,
notification: {
title: "Notification Title",
body: "Notification Body ",
},
};
admin.messaging().send(message);

- 12,745
- 9
- 57
- 95