Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase FCM error: 'InvalidRegistration'

Tags:

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

like image 240
anho Avatar asked May 17 '17 22:05

anho


People also ask

What is Registration_ids in FCM?

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.

What is payload in FCM?

Firebase Cloud Messaging (FCM) is a messaging solution that lets you reliably send messages at no cost to both Android & iOS devices. Using FCM, you can send data payloads (via a message) to a device for a specific application. Each message can transfer a payload of up to 4KB to a client.

How can I get device registration token in firebase?

This requires you to: Add app logic in your client app to retrieve the current token using the appropriate API call (such as token(completion): for Apple platforms or getToken() for Android) and then send the current token to your app server for storage (with timestamp).


1 Answers

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

like image 133
Sunil Garg Avatar answered Sep 19 '22 22:09

Sunil Garg