Menu
Amazon Simple Notification Service
Developer Guide (API Version 2010-03-31)

Send Custom Platform-Specific Payloads in Messages to Mobile Devices

You can use either the Amazon SNS console or APIs to send custom platform-specific payloads in messages to mobile devices. The following sections describe how to use the Amazon SNS console to create and send custom platform-specific payloads for each of the supported notification services. For information on using the Amazon SNS APIs, see Using Amazon SNS Mobile Push APIs and the AWS sample file SNSMobilePush.java, which is included in the snsmobilepush.zip file.

JSON Formatted Message Data

When sending platform-specific payloads in messages using the Amazon SNS console, the data must be key-value pair strings and formatted as JSON with quotation marks escaped. The following example, including formatting and spaces for readability, shows a sample custom message for the GCM platform with key-value pair within the message body and formatted as JSON.

Copy
{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"www.amazon.com" } }" }

When sending messages using the console quotation marks must be escaped (\"), as the following example shows.

Copy
{ "GCM":"{ \"data\":{ \"message\":\"Check out these awesome deals!\", \"url\":\"www.amazon.com\" } }" }

When entered in the Amazon SNS console, the example should look similar to the following:

Copy
{ "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"www.amazon.com\"}}" }

Platform-Specific Key-Value Pairs

In addition to sending custom data as key-value pairs, you can also send platform-specific key-value pairs within the JSON payload. For example, if you wanted to include time_to_live and collapse_key GCM parameters after the custom data key-value pairs included in the data GCM parameter, then the JSON payload without escaped quotation marks would look similar to the following:

Copy
{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"www.amazon.com" }, "time_to_live": 3600, "collapse_key": "deals" }" }

When entered in the Amazon SNS console, the example should look similar to the following:

Copy
{ "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"www.amazon.com\"},\"time_to_live\": 3600,\"collapse_key\":\"deals\"}" }

For a list of the supported key-value pairs in each of the push notification services supported in Amazon SNS, see the following links:

Messages to an App on Multiple Platforms

To send a message to an app installed on devices for multiple platforms, such as GCM and APNS, you must first subscribe the mobile endpoints to a topic in Amazon SNS and then publish the message to the topic. The following example shows a message to send to subscribed mobile endpoints on APNS, GCM, and ADM:

Copy
{ "default": "This is the default message which must be present when publishing a message to a topic. The default message will only be used if a message is not present for one of the notification platforms.", "APNS": "{\"aps\":{\"alert\": \"Check out these awesome deals!\",\"url\":\"www.amazon.com\"} }", "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"www.amazon.com\"}}", "ADM": "{ \"data\": { \"message\": \"Check out these awesome deals!\",\"url\":\"www.amazon.com\" }}" }