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:
registration_ids
, doesn't helpnotification_key
value as a registration ID in the registration_ids
field, doesn't work eitherproject_id
header to our Project Number (as required when creating the notification_key
), still no lucknotification_key
and notification_key_name
in the request, doesn't helpUPDATE: 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With