In Firebase Console I set up audiences based on various user properties and now am able to send notifications to different user segments via console. Is there a way to do the same by http requests to fcm servers? There should be a trick with "to" field, but I couldn't figure it out.

- 565,676
- 79
- 828
- 807

- 111
- 1
- 4
-
What have you done so far? Please edit your post to include the relevant code. – Tom Lord Jun 23 '16 at 15:35
-
1Great question. Answer below. – Frank van Puffelen Jun 23 '16 at 17:16
-
@Viktor Ivanov, check my answer for same http://stackoverflow.com/a/38992689/2122328 – Sandeep Devhare Aug 17 '16 at 12:13
5 Answers
firebaser here
There is currently no way to send a notification to a user segment programmatically. It can only be done from the Firebase Console as you've found.
We're aware that allowing this through an API would expand the potential for Firebase Notifications a lot. So we're considering adding it to the API. But as usual: no commitment and no timelines, since those tend to change as priorities shift.

- 565,676
- 79
- 828
- 807
-
Do I correctly understand that programmatically I can only send data to the "single devices" using registration tokens? Meaning, that I would need to send registration tokens from my mobile devices to my application server? – Maksim Sorokin Jul 03 '16 at 16:08
-
I am reading many posts detailing that you can send notifications to user devices using HTTP post requests via FCM CCS. Is there a way to do this in code, or it is impossible as of now? If it's impossible, why do the FCM docs go into detailed about how to structure a notification with the "to" and "notification" keys when building a JSON structured notification? By reading this set up of JSON structured notifications you are bound to believe that we could wrap up some code and create a notification in our code logic that targets a specific device. @FrankVanPuffelen – i_o Sep 18 '16 at 21:29
-
@FrankVanPuffelen Is there any updates on this? Am searching to do it in back end using curl php. But unfortunately couldn't do it for user segment. Is there any other way to do this without using console? – Learning Sep 28 '16 at 12:21
-
4Are there any updates on this? I mean still push notification through server to user segment is not possible? – VSB Feb 22 '17 at 19:34
This has been a popular request, but unfortunately it is not yet possible. We are looking into this. Please check Firebase Cloud Messaging announcements for any updates in the future.

- 11
- 1
You can try with topic subscriptions. It is not perfect solution but the best for me at this time.
{
"to": "/topics/audience1_subscription"
"data" : {
"title" : "Sample title",
"body" : "Sample body"
},
}

- 2,221
- 1
- 29
- 35
Yes. No solid solutions are available as of now but I have a workaround solution for it. Which is not able to handle every scenario but it will get the work done.
For that, you need to figure out the audience within the app and you need to segment them with topics. Then you can send a push notification for that particular topic via API.
Let's take an example.
Send notifications to users who didn't open the app in the last 7 days
Subscribe to a topic name "app-open?date=09-21-2022"
each time user opens the app. Just unsubscribe from the topic of the last app opened and subscribe to a new topic with the current date. Then you just need to build a topic string based on the current day - 7 to send.
And you can create multiple topics for the same user for different behaviors and use them as topics to send push notifications via API to segmented users.
As there is no limit on topics per user or topics per project. You can create as many as topics you want and use them as your need.

- 19
- 2
Yes.There is trick with the "to" field as mentioned in below.
web URL is: https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key="YOUR_SEVER_KEY"
JSON DATA FORMAT:
{"to": "USER_FIREBASE_TOKEN",
"data": {"message": "This is a Firebase Cloud Messaging Topic Message",}
"notification": {"body": "This is firebase body",}}";

- 7,341
- 10
- 42
- 60

- 447
- 8
- 6