GCM User Notifications
Published in
1 min readAug 7, 2014
Unfortunately documentation about GCM User Notifications is incomplete and sometimes wrong. Here are some server-site curl requests that can be used while using this api.
Creating new notification
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/notification" << EOF
{
“operation”: “create”,
“notification_key_name”: “asdf”,
“registration_ids”: [“<REGISTRATION-ID-FROM-DEVICE>”]
}
EOF
Response
HTTP/1.1 200 OK
{“notification_key”:”<NOTIFICATION-ID>”}
Adding registration id
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/notification" << EOF
{
“operation”: “add”,
“notification_key_name”: “asdf”,
“notification_key”: “<NOTIFICATION-ID>”,
“registration_ids”: [“<REGISTRATION-ID-FROM-DEVICE>”]
}
EOF
Response
HTTP/1.1 200 OK
{“notification_key”:”<NOTIFICATION-ID>”}
Send to a single registration id:
Command
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
{
“registration_ids”: [“<REGISTRATION-ID-FROM-DEVICE>”],
“data”: {},
}
EOF
Response
{“multicast_id”:6938855486830250566,”success”:1,”failure”:0,”canonical_ids”:0,”results”:[{“message_id”:”<SOME_ID>”}]}
Send to a notification id
Command
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
Response
{“success”:1,”failure”:0}
Links
- video — http://youtu.be/owhf42SZadk?t=7m50s
- documentation — http://developer.android.com/google/gcm/notifications.html#response-send (sadly uncomplete and soemtimes wrong)