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
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.
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.
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).
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!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With