Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsubscribe from a topic in FCM Web

I successfully set FCM in my Website and it is working perfectly. I am using JavaScript to send notification to a 'movies' topic by subscribing it.

fetch('https://iid.googleapis.com/iid/v1/'+tokenz+'/rel/topics/movies', {
          method: 'POST',
          headers: new Headers({
            'Authorization': 'key=****'
          })

I don't find any documentation to unsubscribe a topic in web using JS. What is the best way to unsubscribe a single topic and also is there a way to unsubscribe to all topics?

like image 554
deadpool Avatar asked Mar 22 '17 09:03

deadpool


1 Answers

Good question. It never really hit me that there wasn't an advised way/guide to unsubscribe from topics for FCM Web in the documentation.

As you already know, it is stated that in order to subscribe to a topic, you'll have to make use of the Instance ID API. So I figured that you should use the same. I've gone through the docs, but there isn't anything mentioned which to use when unsubscribing a single token from a single/multiple topic(s).

With all that said, what I would suggest for now is to use batchRemove to unsubscribe your specific token from a topic. Example from the docs:

https://iid.googleapis.com/iid/v1:batchRemove
Content-Type:application/json
Authorization:key=API_KEY
{
   "to": "/topics/<YOUR TOPIC NAME HERE>",
   "registration_tokens": ["<YOUR TOKEN HERE>"]
}

I also tried the DELETE API, but it deletes the registration token itself (i.e. invalidates it).

like image 121
AL. Avatar answered Oct 24 '22 22:10

AL.