FCM device group management

I am trying to figure out how to manage FCM device groups from an application server using the REST API.

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

Here is what I can do:

  • Create a new device group with some device tokens
  • Add device tokens to an existing device group

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

  • Ask if a device group exists based on its notification_key_name .

    Workaround 1: if I try to create a group with notification_key_name that already exists, then I get an error message, but this seems like a very hacky way to find out.

    Workaround 2: Keep this information in a different place.

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

    Workaround: As before, store this information elsewhere.

  • Retrieve device tokens ( registration_id ) from the device group.

    Workaround: None.

  • Delete device group.

    Workaround: None.

Thanks!

+8
firebase firebase-cloud-messaging
source share
1 answer
  • Ask if a device group exists based on its notification_key_name .

Your second workaround is the way to go. You must save it on your application server, just as you would for storing registration tokens.


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

Same as workaround above. You must manage these details on your application server. Responsibility for these details lies with the developer. Accepting the steps if the registration device is removed, you will also have to remove it from the application server.


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

I'm not sure what you need here. The documentation contains information about removing registration tokens from a device group:

Add or remove 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 specify the registration tokens to add or remove.

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

HTTP POST Request

For example, to add a device with 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 add or remove a device returns a value of type message_key as:

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

Note : name_of_name is not required to add / remove registration tokens, but it also protects you from accidentally using the wrong notification_key > .Sub>


  • Delete device group.

From the note in the docs above:

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

+5
source share

All Articles