Firebase 401 unauthorized error FCM

Solution 1:

I don't know if someone uses the [Web API Key] as the [YOUR_SERVER_KEY] for POSTMAN test and keep getting '401 Error'. [Web API Key] is not [YOUR_SERVER_KEY].

You should go to your Firebase console and check this:

to get the correct Server key.

Hope it help.

Solution 2:

I noticed from your screenshot that you were using "key: serverKey". Could you try using "key=serverKey" instead?

Also you don't need to have "POST fcm.googleapus.com/fcm/send"; this is not proper json and would explain the error you are seeing. The URL of the request is already defined elsewhere so remove it from the payload.

Solution 3:

I faced the same problem.

the problem was that I was using the legacy server key. when I used the new version of the server key the problem solved.

in your firebase console goto settings -> cloud messaging

then use the new server key. it is longer than the old version key.

Solution 4:

go to https://console.firebase.google.com/u/0/project/[project-name]/settings/cloudmessaging/

Project credentials

you can use Server Key or Legacy server key