0
votes

I want to send notification to specific user when logged in , I use Firebase messaging and I can send notification by console but I want send this notification in Swift code by using send to topic and http request. I couldn't to implement http request to send notification when I run the code in postman I have this error :

The request was missing an Authentification Key (FCM Token). Please, refer to section "Authentification" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.

Error 401

1
the error tells you are missing a FCM token. stackoverflow.com/questions/37787373/…sweekar
i want this in ios not android !mahdi alajwadi
Can you please provide your request code so we can see what might be missing?unkgd
{ "condition": "'mahdi' in topics", "priority" : "high", "notification" : { "body" : "This is a Firebase Cloud Messaging Topic Message!", "title" : "FCM Message" } }mahdi alajwadi
You need to pass the server key to Postman. See stackoverflow.com/questions/39133832/… and other answers in this list: stackoverflow.com/…Frank van Puffelen

1 Answers

1
votes

401 Error pertains to an Authorization Error:

The sender account used to send a message couldn't be authenticated. Possible causes are:

  • Authorization header missing or with invalid syntax in HTTP request.
  • Invalid project number sent as key.
  • Key valid but with FCM service disabled.
  • Request originated from a server not whitelisted in the Server key IPs.

Check that the token you're sending inside the Authentication header is the correct Server key associated with your project. See Checking the validity of a Server key for details.

Make sure you're using the correct Server Key from your Firebase Console, under the Cloud Messaging Tab. Steps below.

  1. Go to your Firebase Console and select the corresponding project.
  2. Then on left-side panel, click on the gear button and select Project Settings.
  3. Then go to the Cloud-Messaging Tab.

The Server Key should be visible from there. This the key that you include in the request when sending a message. Make sure that you're properly setting the headers.

You can also do this using Postman or cURL