Nav Nav
Nav Nav

Reputation: 167

Sending FCM push notification with NodeJs to Topics

I am trying to send FCM with NodeJS using node-gcm module to my mobile client. I am not targeting a specific device. However, I want to send push by using a Topic, but when I call the FCM API, I receive the following:

{ multicast_id: 59360557496141941230,
  success: 0,
  failure: 1,
  canonical_ids: 0,
  results: [ { error: 'InvalidRegistration' } ] }

Here is my code:

var gcm = require('node-gcm');
var serverKey ='XXXXX';
//var serverKey = 'AIzaSyAS9s5VXlut35NNOkPktqoFzx8EsOxIdK4';
var sender = new gcm.Sender(serverKey);

sendFCM('1231231231');

function sendFCM(number){

    var myTopic="phoneNumber_"+number;
    var message = new gcm.Message({
      data: { key1: 'msg1' }
    });

    //callback style
   sender.sendNoRetry(message, { topic: myTopic }, (err, response) => {
    if (err) console.error(err);
    else console.log(response);
   });

}

Upvotes: 0

Views: 1920

Answers (1)

Nav Nav
Nav Nav

Reputation: 167

/topics/ was missing from this line:

var myTopic="phoneNumber_"+number;

solution :

var myTopic="/topics/phoneNumber_"+number;

Upvotes: 1

Related Questions