Josep Sayol
Josep Sayol

Reputation: 417

Managing FCM device groups

I'm trying to figure out how to manage FCM device groups from an app server by using the REST API.

AFAIK these are the updated docs: https://firebase.google.com/docs/cloud-messaging/android/device-group#managing_device_groups

Here's what I can already do:

And this is what I just can't figure out how to do since there's no mention of it in the docs:

Thanks!

Upvotes: 15

Views: 15444

Answers (2)

relie
relie

Reputation: 21

To add another option to the first question, not sure if this was added by FCM after the accepted answer but, in the Managing device groups on the app server section in the Android (and IOS) documentation, there is a part on Retrieving a notification key using a GET request to

https://fcm.googleapis.com/fcm/notification?notification_key_name=appUser-Chris

This returns

{ "error": "notification_key not found" }

if the device group does not exist, or the notification key, otherwise.

Upvotes: 2

AL.
AL.

Reputation: 37768

  • Query whether a device group already exists, based on its notification_key_name.

Your 2nd workaround is the way to go. You should store it in your App server, same where you also store the Registration Tokens.


  • Finding out which device tokens (registration_id) belong to a device group.

Same as the workaround above. You have to manage these details on your App Server. It is the developer's responsibility to manage these details. Matching the actions if the registration device is removed, you'll have to remove it from your App Server as well.


  • Remove device tokens (registration_id) from a device group.

I'm not sure what you need here. The documentation have details on removing registration tokens from the device group:

Adding and removing devices from a device group

To add or remove devices from an existing group, send a POST request with the operation parameter set to add or remove, and provide the registration tokens for addition or removal.

Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

HTTP POST request

For example, to add a device with the registration ID 51 to appUser-Chris, you would send this request:

{
   "operation": "add",
   "notification_key_name": "appUser-Chris",
   "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
   "registration_ids": ["51"]
}

Response format

A successful request to either add or remove a device returns a notification_key like the following:

{
   "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}

Note: notification_key_name is not required for adding/removing registration tokens, but including it protects you against accidentally using the incorrect notification_key.


  • Remove a device group.

From the note in the docs above:

Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

Upvotes: 15

Related Questions