Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • 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 since there's no mention of it in the docs:

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

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

    Workaround 2: Store that information by myself somewhere else.

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

    Workaround: as before, store that information by myself somewhere else.

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

    Workaround: none.

  • Remove a device group.

    Workaround: none.

Thanks!

like image 260
Josep Sayol Avatar asked Feb 28 '17 17:02

Josep Sayol


1 Answers

  • 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.

like image 176
AL. Avatar answered Oct 12 '22 23:10

AL.