3

Good day,

I am trying to use this URL from FCM to send messages:

https://fcm.googleapis.com/fcm/send

With a header of

    Authorization value of **key:*Key from Firebase Console***
    Content-Type: **application/json**

The body consist of this:

    {
       "to" : "MyKey generated",
       "notification" : {
       "body" : "Hey",
       "title" : "Hey"
    }  
 }

But the result i always received is this:

     {
        "multicast_id": 7942550122547405787,
        "success": 0,
        "failure": 1,
        "canonical_ids": 0,
        "results": [
            {
               "error": "MismatchSenderId"
           }
      ]
    }

The server key I got is from here:

Server Key

My URL reference is the docs in FCM server.

I am testing this in Postman. Did I miss something? Thanks

KENdi
  • 7,576
  • 2
  • 16
  • 31
Jeric John Romero
  • 103
  • 1
  • 1
  • 8
  • 1
    try this https://stackoverflow.com/a/43912791/1548824 – akhilesh0707 Jul 05 '17 at 13:53
  • 2
    Possible duplicate of [Firebase MismatchSenderID when Authorization key is my Server key](https://stackoverflow.com/questions/43244901/firebase-mismatchsenderid-when-authorization-key-is-my-server-key) – AL. Jul 06 '17 at 03:36
  • 1
    Does this answer your question? [FCM getting MismatchSenderId](https://stackoverflow.com/questions/37863106/fcm-getting-mismatchsenderid) – David Oct 16 '21 at 00:49

7 Answers7

6

According to the docs

A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.

So it sounds like you are trying to send a push notification to an ID that is not associated with the sender ID. You should verify that you have the correct keys in the correct places

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • Does that mean that the token I am receiving from mobile app does not associated to the sender ID? I am working with the backend side, unfortunately, I have to confirm this with the mobile dev, right ? – Jeric John Romero Jul 05 '17 at 14:15
  • That means you are using the wrong server key with with the sender id for your app or you are using an old id that was created with a different sender id. Since the sender id is needed in the app to create the instance id you have keys messed up somewhere. I would verify your keys in the project settings in firebase console – tyczj Jul 05 '17 at 14:22
  • Another test: the token I used in postman is the same token I use in the notification link in firecloud. but it works when notification function of firecloud – Jeric John Romero Jul 05 '17 at 14:28
  • I see. Keys may be messed up in the app. Not so sure how to do this, but I'll ask the mobile devs for this. – Jeric John Romero Jul 05 '17 at 14:30
  • 1
    I had this error, and I think it's that the FCMToken that I received from the mobile app (which got it from firebase) that I had saved to my backend was wrong, and saving the correct token fixed this error – ehacinom Nov 01 '18 at 17:59
3

Sounds like Google Services on your Android app has been configured incorrectly.

Log into Firebase console, open your project (click the gear icon). Under General tab, scroll down to "Download the latest config file" and click on the button to download google-services.json (which should include the correct project and sender ID)

Send this to your mobile devs to include in the app and once the app's sent a valid push token, try sending again.

Jay Sidri
  • 6,271
  • 3
  • 43
  • 62
1

the header must be like this

Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

to check the validity of a server key

api_key=YOUR_SERVER_KEY

curl --header "Authorization: key=$api_key" \
       --header Content-Type:"application/json" \
       https://fcm.googleapis.com/fcm/send \
       -d "{\"registration_ids\":[\"ABC\"]}"

if everything is ok so you need to recheck the senderId

Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44
1

This error is due to invalid tokens I solved this, enter the token correctly

fa esavand
  • 11
  • 2
1

Posting FCM through POSTMAN

Authorization: key=YOUR-SERVER-KEY
Content-Type: application/json

enter image description here

Now click on Body than select Row and add value as object like below
Make sure Row is in JSON(application/json)

enter image description here

{
"to": "cpa8cZPjq-w:APA91bF122f1Rnhu9v47bL
YMajaNTHAIU5SzItDwTy9o2MCIveG0PlK78VPvp3d
CqjwnUKZ4
ngi1trSyM3_aXttW62iknFfbPGtjRLhZr6wq-3qFdboz8gzdOGPz**********",

"notification": {

"body": "Hello",
"title": "This is test message."
}
}

POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com

enter image description here

1

This problem simply means server and client used 2 different firebase projects. It most likely happens when you accidentally push wrong keys and mix up your Development, Staging or Production environments.

Steps to fix:

  1. Check your server make sure the keys in firebase admin / fcm matches your target environment
  2. Check your client make sure it's generating the push tokens using the same target environment

You can confirm the client environment against the server by sending a test push notification using the generated push token in your firebase console. You will only receive the test notification if the push token is used in the correct Firebase project.

David
  • 151
  • 1
  • 5
1

Downloading google-services.json and GoogleService-info.plist files from the General tab of the Firebase console solved the problem.

1

Don't download the file that comes while creating the app. There might be chances for mismatching sender ids. So, the best way is to download the files from the general tab and place them in their respective folders.

2

Lahfir
  • 145
  • 2
  • 15