GCM User Notifications

Jacek Marchwicki
Appunite Labs
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

--

--

Appunite Labs
Appunite Labs

Published in Appunite Labs

We believe in knowledge sharing and software as a tool to improve companies and peoples’ lives. We take lessons from our daily challenges and share that experience and knowledge to help you build better products.