Firebase FCM error: 'InvalidRegistration'

I am currently trying to send a PushNotification to a Device Group using FCM with the help of Firebase Cloud Functions but once the notification is sent, it returns with code 200 but with failure :

SUCCESS response= {
multicast_id: 8834986220110966000,
success: 0,
failure: 1,
canonical_ids: 0,
results: [ { error: 'InvalidRegistration' } ] 
}

Here is the code I am using to send this notification... what am I missing?

const options = {
    method: 'POST',
    uri: 'https://fcm.googleapis.com/fcm/send',
    headers: {
       'Authorization': 'key=' + serverKey,
    },
    body: {
       to: groupId,
       data: {
        subject: message
       },
       notification: {
         title: title,
         body: body,
         badge: 1,
        },
       content_available: true
    },
    json: true
};

return rqstProm(options)
    .then((parsedBody) => {
        console.log('SUCCESS response=', parsedBody);
    })
    .catch((err) => {
        console.log('FAILED err=', err);
    });

Where JSON values title, body, subject, message are String


In my case, I was sending notifications to topic ("topics/my-topic"). I was missing prepending / in the starting of topic so I was getting the same issue. SO topic should be /topics/my-topic.

May be this helps!!


There is an easier way to send a message to a device group from a Cloud Function. Use admin.messaging().sendToDeviceGroup(). Sample code and instructions are in this guide.

I think your current method is failing because there is something wrong with the group notification key provided in groupId. It should be the string key value that was returned when you created the device group. The error codes are listed in this table. For 200/InvalidRegistration it says:

Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.