How to get "registration_ids" from Firebase FCM?

The sample request you included:

https://android.googleapis.com/gcm/notification
Content-Type:application/json
Authorization:key=API_KEY
project_id:SENDER_ID

{
   "operation": "create",
   "notification_key_name": "appUser-Chris",
   "registration_ids": ["4", "8", "15", "16", "23", "42"]
}

is for creating a Device Group.

The registration_ids parameter refers to the Registration Tokens you want to add in that specific Device Group. Described as:

An ID generated by the FCM SDK for each client app instance. Required for single device and device group messaging. Note that registration tokens must be kept secret.

Meaning that it is generated on the client app side and acts as the identifier of that specific device (client app instance).

To send downstream messages to a device group, simply make use of the to parameter:

This parameter specifies the recipient of a message.

The value can be a device's registration token, a device group's notification key, or a single topic (prefixed with /topics/). To send to multiple topics, use the condition parameter.

passing the notification_key as value.


"registration_ids" is an array of the registration tokens acquired by calling FirebaseInstanceId.getInstance().getToken() on a device. If you put multiple registration tokens in the array, the same push notification will be sent to each.

If you only want to send a notification to one device with a registration_id of 4, your "registration_ids" array need only contain one value like so: "registration_ids": ["4"]

If you want to send a notification to multiple devices, call FirebaseInstanceId.getInstance().getToken() on each device to get the token then populate the array with values like you already have.