You can retrieve the notification_key for a device group if you know the notification_key_name that was used when you created it. Ref: https://firebase.google.com/docs/cloud-messaging/android/device-group
Use this:
https://android.googleapis.com/gcm/notification?notification_key_name=your-key-name
Ref: https://groups.google.com/forum/#!topic/firebase-talk/ytovugx8XNs
For example:
let options = {
url: 'https://android.googleapis.com/gcm/notification?notification_key_name=the_name',
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": "key=" + authorizationKey,
"project_id": projectId
}
};
request(options, function (error, response, body) {
if (!error) {
res.json(body);
}
else {
res.json(error);
}
});
One thing I found when using this call was that the notification_key returned was always different, but I was able to use it successfully to add or remove registration_ids.
I'll add some additional information from comments I made earlier:
- I've had quite a bit of trouble with device groups. The only way to delete a device group is to remove all the notifications keys it contains. If you lose track of a notification key that you have added to the device group then deleting that device group is impossible, as there is no way currently to get a list of the notification keys in a device group.
- The device group is a very good mechanism for sending messages to multiple devices (see @AL.'s comment for another method). I also store in the database the registration_ids for each device group. The reason for that is if the user deletes their account for my app I also delete their device group so that the device group name can be reused.