Firebase FCM error: 'InvalidRegistration'

40,406

Solution 1

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.

Solution 2

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!!

Share:
40,406

Related videos on Youtube

anho
Author by

anho

Software engineer with a taste for mobile applications.

Updated on January 14, 2022

Comments

  • anho
    anho over 2 years

    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

  • mic
    mic almost 7 years
    This really doesn't answer the question I am also getting the same error using a completely different way from a node JS back end.
  • ios_dotnet_superuser
    ios_dotnet_superuser over 4 years
    i have the same problem, the token given by fcm from mobile app give this error on server, i use FirebaseMessaging (3.4.0)
  • Vishal Kumar
    Vishal Kumar over 3 years
    where should we listen this on android when sending to /topics/my-topic. Should we use my-topic
  • Ahmad Khan
    Ahmad Khan about 2 years
    This answer doesn't help. I'm trying to do the same using Postman but I'm getting the same output as written in the question. Also, I'm not using any topic.