Developer Console

Real-Time Notifications Examples

This page provides sample Real-Time Notifications JSON responses to your HTTPS endpoint for subscriptions, consumables, and entitlements.

Subscription

In this example, a customer creates a new subscription for your app and you receive a SUBSCRIPTION_PURCHASED Real-Time Notification.

{
 "Type" : "Notification",
 "MessageId" : "b1c4d9bb-0fd9-54b2-8f74-8e59c91e396a",
 "TopicArn" : "arn:aws:sns:us-east-1:033616359524:LT0XA",
 "Message" : "{\"appPackageName\":\"com.example.amazonsdkapivalidator3\",\"notificationType\":\"SUBSCRIPTION_PURCHASED\",\"appUserId\":\"io9oFdzmCSMuKk_pp9pYccoIHRfc6kSAAYaNo51xZrg=\",\"receiptId\":\"koxIn_LO2u7rc-_MF40hKz1vqSSJSlitfTNDeH_JAs8=:3:11\",\"relatedReceipts\":{},\"timestamp\":1600701569824,\"betaProductTransaction\":false}",
 "Timestamp" : "2020-09-21T15:19:35.686Z",
 "SignatureVersion" : "1",
 "Signature" : "EXAMPLEab123...",
 "SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem",
 "UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:033616359524:LT0XA:a745747c-8230-4cd2-84c6-d0e7df9f1ca1"
}

Consumable

In this example, a customer buys a consumable from your app and you receive a CONSUMABLE_PURCHASED Real-Time Notification.

{
    "Type" : "Notification",
    "MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324",
    "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
    "Message": "{\"receiptId\":\"bsw3Wi6w17Ngdabggckh61kmmFhfwlfT9nPZeLfh83k=:1:11+Sheet2!A1+\",\"relatedReceipts\": {},\"appUserId\":\"kyplB1fdRX1m6/GNAVW0l6jv9Nl1V/GemSopKBHM84w=\",\"notificationType\":\"CONSUMABLE_PURCHASED\",\"appPackageName\":\"com.playrix.gardenscapes.amazon\",\"timestamp\":1588086967189, \"betaProductTransaction\":false,}",
    "Timestamp" : "2012-05-02T00:54:06.655Z",
    "SignatureVersion" : "1",
    "Signature" : "EXAMPLEw6JRN...",
    "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
    "UnsubscribeURL" : "UnsubscribeUrl"
}

Entitlement

In this example, a customer buys an entitlement from your app and you receive an ENTITLEMENT_PURCHASED Real-Time Notification.

{
    "Type" : "Notification",
    "MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324",
    "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
    "Message": "{\"receiptId\":\"bsw3Wi6w17Ngdabggckh61kmmFhfwlfT9nPZeLfh83k=:1:11+Sheet2!A1+\",\"relatedReceipts\": {},\"appUserId\":\"kyplB1fdRX1m6/GNAVW0l6jv9Nl1V/GemSopKBHM84w=\",\"notificationType\":\"ENTITLEMENT_PURCHASED\",\"appPackageName\":\"com.playrix.gardenscapes.amazon\",\"timestamp\":1588086967189, \"betaProductTransaction\":false,}",
    "Timestamp" : "2012-05-02T00:54:06.655Z",
    "SignatureVersion" : "1",
    "Signature" : "EXAMPLEw6JRN...",
    "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
    "UnsubscribeURL" : "UnsubscribeUrl"
}

Duplicate Notifications

Generally, each Real-Time Notification is delivered to each specified endpoint once. However, the distributed nature of Amazon SNS and transient network conditions can cause an occasional duplicate message. Make sure to design the application so that duplicate notification messages do not create any errors or inconsistencies.

Code Snippets with Amazon AWS SDK

AWS reference documentation:

public class SnsServletProcessor implements HttpServletProcessor {
    private final SnsMessageManager messageParser = new SnsMessageManager("us-east-1");

    @Override
    public void process(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
        messageParser.handleMessage(httpRequest.getInputStream(), new DefaultSnsMessageHandler() {
            @Override
            public void handle(SnsNotification snsNotification) {
                  // Business logic to process the notification message                   
            }
        };
    }
}

Last updated: Dec 08, 2021