Bruno
Bruno

Reputation: 191

FCM notification with topic server side not received on client

I tried a sample code to test the push notification system with Firebase and it's working well except one thing.

This is a example call:

link: https://fcm.googleapis.com/fcm/send
POST method

Header field:
Content-Type : application/json
Authorization : key=MY_SERVER_KEY (the new one)

Body:
{
    "to": "/topics/topik",
    "data": {
        "title": "This is a Firebase Cloud Messaging Topic Message!",
        "content-text": "This is a Firebase Cloud Messaging Topic Message!"
    }
}

or

Body:
{
    "to": "/topics/topik",
    "data": {
        "message": "This is a Firebase Cloud Messaging Topic Message!"
    }
}

the result on send action is something like this

{
  "message_id": 7150560334538835864 (SUCCESS!)
}

but no notification arrives in any device. I tried to debug the onReceive method, but nothing happens.

Any idea?

Upvotes: 2

Views: 1714

Answers (1)

Diego Giorgini
Diego Giorgini

Reputation: 12717

Are you trying to send data-messages or notification-messages?
see: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

If you want to send notification-messages (the type of messages sent by the notification console)
the payload you wrote in the question is wrong. Try replacing data with notification:

Body:
{
    "to": "/topics/topik",
    "notification": {
        "title": "Hello",
        "body": "This is a Firebase Cloud Messaging Topic Message!"
    }
}

Upvotes: 1

Related Questions