Friday, 21 April 2017

400 Bad Request Error while subscribing users to topic in cloud functio

I'm trying to subscribe users to firebase topic on the cloud function. So according to official docs I tried the following code

 request({
        method: 'POST',
        url: "https://iid.googleapis.com/iid/v1:batchAdd",
        json: true,


        headers: {
            'Content-Type':'application/json',
            'Authorization':'key=server key,

        },

        body: JSON.stringify({

          "to": "/topics/name",
          "registration_tokens": ["token value"]

        })
            }, function (error, response, body){
        console.log('error:', error);
        console.log('statusCode:', response && response.statusCode);
        if (response.statusCode >= 400) {
            console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage);
          }
    });

But it's giving 400 status code instead of 200. Thank you.



via Doge

No comments:

Post a Comment