Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM User Notifications: Missing "registration_ids" field

Our project has been whitelisted for testing the the new GCM User Notifications API that allows grouping Registration IDs to a single "notification key" that can then be used to send messages to all devices owned by the user.

However, when I send a request like this:

POST /gcm/send
Authorization: key=…
Content-Type: application/json

{"notification_key": "…",
 "data": {…}
}

I get an error response:

400 Bad Request

Missing "registration_ids" field

Sending a message using the registration_ids field instead of the notification_key fixes the problem (and the messages get delivered), but the whole point of using the User Notifications API was to use the notification_key instead of the registration_ids.

From the documentation:

registration_ids: […] A request must include a recipient—this can be either a registration ID, an array of registration IDs, or a notification_key. Required.

notification_key: A string that maps a single user to multiple registration IDs associated with that user. This allows a 3rd-party server to send a single message to multiple app instances (typically on multiple devices) owned by a single user. A 3rd-party server can use notification_key as the target for a message instead of an individual registration ID (or array of registration IDs). […] Optional.

The above example uses the HTTP connection server at https://android.googleapis.com.

So far I tried:

  • including an empty array for registration_ids, doesn't help
  • sending the notification_key value as a registration ID in the registration_ids field, doesn't work either
  • setting the project_id header to our Project Number (as required when creating the notification_key), still no luck
  • using CCS (XMPP) instead of HTTP to communicate with the GCM API server, but unfortunately the IP is blocked on Google App Engine
  • including both notification_key and notification_key_name in the request, doesn't help

UPDATE: As per suggested here, I also tried posting the payload to /gcm/notification, with the "operation": "send" property included in the JSON request payload. Still no help. Now I get:

{"error":"Missing \"registration_ids\" field"}

Same thing, only this time it is sent back JSON-encoded.

like image 718
Attila O. Avatar asked Nov 01 '13 04:11

Attila O.


1 Answers

The documentation is buggy, you have to use this request:

curl -vvv -X POST --header "Content-Type: application/json" --header "project_id: <YOUR-PROJECT-ID>" --header "Authorization: key=<YOUR-PROJECT-SECRET-KEY>" --data @- "https://android.googleapis.com/gcm/send" << EOF
{ 
   "to": "<NOTIFICATION-ID>",
   "data": {},
}
EOF

please see my blog post https://medium.com/appunite-edu-collection/d7df385b0ff4 for more details

like image 81
Jacek Marchwicki Avatar answered Oct 23 '22 18:10

Jacek Marchwicki