Seller Notifications

Notification APIs can be used to receive notification from Snapdeal at your web end point. You need to first register your end point with Snapdeal (Contact Snapdeal Seller API team to register your end point). Currently only the following type of notifications are available

  1. New Order Notifications - To receive a notification whenever a new order is made your registered seller.

  2. New Return Notifications - To receive notification whenever a new buyer/courier return has happened for your registered seller

Once your end point is registered, you can call Seller Notification registration API to register/de-register notifications for one of your authorized seller.

Notification Subscription

Snapdeal can send Push Notifications to be consumed over HTTPS. The client has to setup the Web infrastructure to consume the messages that is like subscribing to a topic.

Subscribe as a Client and Register Sellers to receive notification messages.
Basically, there are two types of messages sent:

  1. Subscription Confirmation
  2. Notification
    Subscription Confirmation is for the Client Subscriber to subscribe to a topic on HTTPS endpoint. Subscription Confirmation is a one-time message when confirmed by the Client is subscribed to the topic. But the Notification Type is for every notification message that the Seller/User has registered for.

The Push Notification System is based on Amazon SNS and can refer to the link for more understanding.

To enable Snapdeal to Send Push Notifications to the subscribed topic over HTTPS involves the following steps:

  1. Make sure the HTTPS end point is ready to process messages
  2. Subscribe the HTTPS end point by sending an email to Snapdeal
  3. Confirm the subscription
  4. Register Sellers to receive the notifications

Step 1: Make sure the HTTPS end point is ready to process messages

This is a first step for the client to build the Web Infrastructure to consume messages. This should have capability to receive HTTP POST Requests. Create a web application like Java Servlet that processes the Requests from Amazon SNS and confirm the subscription.

Step 2: Subscribe the HTTPS end point by sending an email to Snapdeal

Send an email to Amitoj Singh amitoj.singh@snapdeal.com by providing the following details.
clientId and HTTPS endpoint.
Then the team in Snapdeal will initiate the process of subscription and the next step confirms that through a code or by hitting the confirmation URL See next.

Step 3: Confirm the subscription

Unless the subscription is confirmed, Snapdeal cannot send notifications to the HTTPS endpoint. The Message type Subscription Confirmation is received as the first message to the HTTPS endpoint. One can either use the Subscription URL from the response to subscribe or use a code to do that. See below for the sample message. It is preferred to use Code for subscription and the sample is provided.

a. SubscriptionConfirmation

The code reads HTTP Headers and looks for x-amz-sns-message-type, which tells you the type of message that Snapdeal has sent to you. By looking at the header, you can determine the message type without having to parse the body of the HTTP request. There are two types that you need to handle: SubscriptionConfirmation and Notification as explained above:

Subscription Confirmation

POST / HTTP/1.1
x-amz-sns-message-type: SubscriptionConfirmation
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent

{
  "Type" : "SubscriptionConfirmation",
  "MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
  "Token" : "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
  "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
  "Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
  "SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
  "Timestamp" : "2012-04-26T20:45:04.751Z",
  "SignatureVersion" : "1",
  "Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
  "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
  }
b. Notification
Notification  

POST / HTTP/1.1
x-amz-sns-message-type: Notification
x-amz-sns-message-id: da41e39f-ea4d-435a-b922-c6aae3915ebe
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55
Content-Length: 761
Content-Type: text/plain; charset=UTF-8
Host: ec2-50-17-44-49.compute-1.amazonaws.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent

{
  "Type" : "Notification",
  "MessageId" : "da41e39f-ea4d-435a-b922-c6aae3915ebe",
  "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
  "Subject" : "",
  "Message" : "{JSON}",
  "Timestamp" : "2012-04-25T21:49:25.719Z",
  "SignatureVersion" : "1",
  "Signature" : "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=",
  "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
  "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55"
}

The Message element from the above Response will contain JSON string for every Event Type. Sample message response for New Order is below:

New Order 

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"New Order ",
  "sellerCode":"8f7f72",
  "params":
  {
    "orderItem":"iphone",
    "handoverDate":"12 Jan,2015",
    "siStatusCode":"4354",
    "subOrderCode":"575",
    "fulfillmentMode":"ONESHIP",
    "packageReferenceCode":"6876",
    "orderCategory":"pending",
    "count":"3"
  },
  "notificationType":"OD05",
  "notificationSystem":"ORDERS"
}

Entire Code Sample to Subscribe and Read Notification

@RequestMapping(value = "/push", method =
RequestMethod.POST, produces = { "application/json" })
public void processNotification(HttpServletRequest request,HttpServletResponse response) throws Exception {
// This header x-amz-sns-message-type contains whether it is
// Notification or SubscriptionConfirmation
String messagetype = request.getHeader("x-amz-sns-message-type");
// If message doesn't have the message type header, don'tprocess it.
if (messagetype == null)
return;
Scanner scanner = new Scanner(request.getInputStream());
StringBuilder sb = new StringBuilder();
while (scanner.hasNextLine()) {
sb.append(scanner.nextLine());}
InputStream bytes = new
ByteArrayInputStream(sb.toString().getBytes());
Map<String, String> messageMap = new ObjectMapper().readValue(bytes,Map.class);
// Process the message based on type.There will be two types of message type
//Notification and SubscriptionConfirmation
if (messagetype.equals("Notification")) {
// Processing the message Received
if (messageMap.get("Message") != null) {
String headers = messageMap.get("Message");
Gson gson = new GsonBuilder().serializeNulls().create();
CustomHeaders customHeaders = gson.fromJson(headers,CustomHeaders.class);
// Verifying the Whether notification is from valid user or not
// Constructing the hash to verify
//Hash should contain epoch time in the headers field,endpoint url and the HTTP request method
//e.g. https://partner.api.endpoint is the enpoint that uses POST method ,the hash will be contructed as follow
String sdsignature = customHeaders.getEpochTime()
+ "https://partner.api.endpoint/push" + "POST";
String hash = SHA1(sdsignature);
// Decoding the authorization to get hash from sender
String authorization = customHeaders.getAuthorization();
String base64deoded = new String(
Base64.decodeBase64(authorization));
// Matching both the hashes
// in case hash is not matched return
if (base64deoded.split(":")[1].equals(hash)) {}
else
return;
}
//In othe case if the message type is subcriptionConfirmation,you have to confirm the SubscribeURL to continue receiving the message
else if (messagetype.equals("SubscriptionConfirmation")) {
Scanner sc = new Scanner(
new
URL(messageMap.get("SubscribeURL")).openStream());
StringBuilder sb1 = new StringBuilder();
while (sc.hasNextLine()) {
sb1.append(sc.nextLine());
}
}
return;
}

Step 4: Register Sellers to receive notifications

1. Register a Seller
POST /notification/subscribe/seller
Response :
{
   "metadata": {
       "requestId": "xxxx-xxxx-xxxx-xxxx",
       "message": "yyyyyyyyy",
       "clientId": "partnerId",
       "responseTime": 123,
       "uri": "PUT ………………………..."
   },
   "payload": {
   }
}

Status 200
2. Deregister a Seller
DELETE /notification/subscribe/seller
Response :
{
   "metadata": {
       "requestId": "xxxx-xxxx-xxxx-xxxx",
       "message": "yyyyyyyyy",
       "clientId": "partnerId",
       "responseTime": 123,
       "uri": "DELETE ………………………...”
   },
   "payload": {
   }
}

Status 200

📘

Note :

For all the Seller Notifications Apis we need to give X-Seller-Authz-Token,X-Auth-Token,clientId as Header parameters

SubSystem Notification Message Types

Currently we are providing 5 types of Notifications

1.New Order Notifications
2.New Payment Notifications
3.Payment Cancelled Notifications
4.Buyer Return Notifications
5.Courier Return Notifications

1.New Order Notifications

This Notification sent to the seller when new order is placed.

New Order Notification message:

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"New Order ",
  "sellerCode":"8f7f72",
  "params":
  {
    "orderItem":"iphone",
    "handoverDate":"12 Jan,2015",
    "siStatusCode":"4354",
    "subOrderCode":"575",
    "fulfillmentMode":"ONESHIP",
    "packageReferenceCode":"6876",
    "orderCategory":"pending",
    "count":"3"
  },
  "notificationType":"OD05",
  "notificationSystem":"ORDERS"
}

2.New Payment Notifications

This Notification sent to the seller when new payment is initiated.

New Payment Notifications message:

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"New Payment Initiated",
  "sellerCode":"8f7f72",
  "params":
  {
    "amount":"19423.5",
    "paymentMode":"COD
  },
  "notificationType":"PY01",
  "notificationSystem":"PAYMENTS"
}

3.Payment Cancelled Notifications

This Notification sent to the seller when payment is cancelled.

Payment Cancelled Notifications message:

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"Payment Cancelled",
  "sellerCode":"8f7f72",
  "params":
  {
    "amount":"55",
    "paymentMode":"COD",
    "paymentSettlementDate":"12/12/2015",
    "erpSystemId":"57567"
  },
  "notificationType":"PY02",
  "notificationSystem":"PAYMENTS"
}

4.Buyer Return Notifications

This Notification sent to the seller when there is a buyer return.

Buyer Return Notifications message:

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"New Return",
  "sellerCode":"8f7f72",
  "params":
  {
    "returnStatus":"INPROCESS",
    "returnType":"IpHone",
    "subOrderCode":"32513628",
     "returnItem":"iphone"
  },
  "notificationType":"RT01",
  "notificationSystem":"RETURNS"
}

5.Courier Return Notifications

This Notification sent to the seller when there is a courier return.

Courier Return Notifications message:

"Message" : 
{ 
  "epochTime":1455877575,
  "authorization":"dGVzdFBhcnRuZXJHb3ZpbmRhOjZlODNkMjQ2ZjQxNDhkM2Y0MTU1NDRkZjk3MzIxY2RiNDczYWE3ODU\\u003d",
  "title":"New Return",
  "sellerCode":"8f7f72",
  "params":
  {
    "returnStatus":"PENDING",
    "returnType":"Courier",
    "subOrderCode":"32513698",
    "returnItem":"iphone"
  },
  "notificationType":"RT02",
  "notificationSystem":"RETURNS"
}