Amazon Simple Notification Service
Developer Guide

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 about using the Amazon SNS APIs, see Using Amazon SNS Mobile Push APIs and the AWS sample file, which is included in the 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 FCM platform with key-value pair within the message body and formatted as JSON.

{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"" } }" }

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

{ "GCM":"{ \"data\":{ \"message\":\"Check out these awesome deals!\", \"url\":\"\" } }" }

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

{ "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"\"}}" }

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 FCM parameters after the custom data key-value pairs included in the data FCM parameter, then the JSON payload without escaped quotation marks would look similar to the following:

{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"" }, "time_to_live": 3600, "collapse_key": "deals" }" }

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

{ "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"\"},\"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 FCM 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, FCM, and ADM:

{ "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\":\"\"} }", "GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"\"}}", "ADM": "{ \"data\": { \"message\": \"Check out these awesome deals!\",\"url\":\"\" }}" }