Send FCM notifications to all user with POSTMAN

Viewed 4921

how can I send a notification to all my users without using the console? I've seen POSTMAN but I need a token to be able to send notifications so I don't think it's a solution. Any recommendation?

{
    "to":"dj5qoswwRdGUrUVdsrWuDU:APA91bH97tPuf5c27Yxq7ZOk8imVDHAV2CE-jBxxWolGtaKrKW2LIf_0VzDgFSQGwTN852Nst0TYWDl4bEdxRzJ8olowZAEFNC_D-fIWYviRPNROjkrUQyY5-32RKohzZvfFbEcKzb49",
    "data":{
        "title": "Notificacion PostMan",
        "body": "Notificacion PostMan Body"
    }
}

this is an example of what I did in POSTMAN, it work for an specific user, I need to send to all muy users.

2 Answers

You can do it like this, First you have to subscribe to a topic from your devices like below,

    FirebaseMessaging.getInstance().subscribeToTopic("all")
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        //Successfully Subscribed to Notification Service
                    }else{
                    //Subscription  Notification Service failed
                    }
                }

Then you can send the FCM message to all subscribed devices like this,
Don't forget to add follwing headers to postman,
Authorization: key=your_firebase_key
Content-Type: application:json

{
  "to": "/topics/all",
  "priority": "high",
  "notification": {
    "title": "Emergency Alert!",
    "body": "body"
  },
    "data" : {
      "your_custom_data" : "data",
    }
}

You can't send notifications to all users through postman or SDK. You have to post notification to topics.

Ideally this situation hardly happens. When the new user starts to use your application, user can be mapped to one or more topics based on their interest. So, you can fit the all users into topics.

There is another concept called multicast message. Read about that also before deciding about topics. But, there is no way to send to all users through postman without the token or topic name.

https://firebase.google.com/docs/cloud-messaging/send-message

Related