Search code examples
google-cloud-messagingpublish-subscribe

"Topic name format is invalid" when trying to subscribe to GCM topic


I am trying to subscribe my app instance for a topic as described here. Creating a relation mapping for one app instance works ok.

Problem appears when I am trying to create relation mapping for multiple app instances. GCM returns HTTP status 400 with error "Topic name format is invalid" regardless the fact that I match regular expression for topic name described here.

Even the example POST request from documentation is not working for me again with same error message and I can not find any topic name for which request would pass successfully.

Request

https://iid.googleapis.com/iid/v1:batchAdd
Content-Type:application/json
Authorization:key=API_KEY
{
   "to": "movies",
   "registration_tokens": ["nKctODamlM4:CKrh_PC8kIb7O...", "1uoasi24:9jsjwuw...", "798aywu:cba420..."],
}

Response

HTTP 400 Bad Request
{
   "error": "Topic name format is invalid"
}

Same situation happens for batchRemove request.


Solution

  • The GCM documentation insists you use the prefix /topics/ before your own choice of topic name.

    So in your case, your apps need to specify the string /topics/movies during the client-side registration process, and the first line of your JSON in the server's POST request you have detailed above needs to be "to": "/topics/movies",