39

I'm using firebase console and can send only Notification messages using it.

Is there a way to send data messages using the same?

Aanchal1103
  • 917
  • 8
  • 21
amodkanthe
  • 4,345
  • 6
  • 36
  • 77

4 Answers4

29

The Firebase Notifications Console can only be used to send notification messages. It cannot be used to send data messages.

See the table in message types in the Firebase documentation:

Notification message

Use scenario: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.

How to send:

  1. Use your app server and FCM server API: Set the notification key. May have optional data payload. Always collapsible.

  2. Use the Notifications console: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data in the Notifications console. Always collapsible.

Data message

Use scenario: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.

How to send:

  • Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.
Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Wrong answer.. You can use it to update DB if he will use Messaging API ("downstream msg") – Nirel Nov 21 '16 at 19:43
  • 13
    You can definitely send downstream data messages with Firebase Cloud Messaging by sending a POST request to the HTTP endpoint. But you cannot send data messages from the [Firebase Notifications Console](https://console.firebase.google.com/project/_/notification), which is what the question is about. – Frank van Puffelen Nov 22 '16 at 05:22
27

You can test both notification message and data message using Postman(rest client for testing http request).See screen shots:

enter image description here

In header pass:

key:Content-Type, value:application/json
key:Authorization:key=<Server key>
Shadow
  • 33,525
  • 10
  • 51
  • 64
Mohd Haseen
  • 279
  • 3
  • 3
22

Please look here: Firebase push notifications update DB, my post from June.

In conclusion, you need send HTTP POST request to https://fcm.googleapis.com/fcm/send

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
"score": "5x1",
"time": "15:10"
},
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
Community
  • 1
  • 1
Nirel
  • 1,855
  • 1
  • 15
  • 26
  • 3
    This answer doesn't fit in the context of this question. Please check the question asked - *he specifically asks about sending data message using console which is not possible*. – Nishant Dubey Nov 22 '16 at 05:35
  • 1
    if you want to send a data message to a specific topic, the value of the property "to" must be in the form of "/topics/TOPIC_ID" , otherwise you will get an error – Apperside Jan 09 '18 at 08:59
  • 1
    Exactly what I needed! – enyciaa Dec 31 '18 at 11:33
  • "Upvote" because of providing an alternative! Please add a note saying "It's not possible to send data messages from FB Console atm and providing an alternative instead" in your answer to complete it. – Ayyappa Mar 20 '19 at 03:32
6

You can now send notification message via the console. Note that it is different from data messages; notification messages only trigger the onMessageReceived callback when the app is in the foreground.

They are inside the advanced options tab on the compose message screen.

enter image description here

Just expand it and type your key/value map.

enter image description here

These will be included into the data field of the notification.

oldergod
  • 15,033
  • 7
  • 62
  • 88
  • 27
    This doesn't work properly. If your app is in the background you won't receive a callback to 'onMessageReceived' even though you are supposed to if you include 'data'. – Wise Shepherd Sep 19 '17 at 18:13
  • @WiseShepherd I actually noticed the same problem yesterday, it can only send _notification message_ and not _data message_. I updated my answer. – oldergod Sep 19 '17 at 23:27
  • This works only when app is in foreground. When app is in background, it considers only Notification data from payload and ignores data part. This leads to no control to the app as notification type messages will be handled by system alone. Only option is to use an external server of your own or send from a rest client. – Ayyappa Mar 20 '19 at 04:09