Amazon Marketplace Web Service (MWS) API Call

Document created by ruchika_yadav Employee on Feb 20, 2017Last modified by Adam Arrowsmith on Mar 10, 2017
Version 4Show Document
  • View in full screen mode

This article explains Amazon Marketplace Web Service (MWS) API calls and how to implement the setup in AtomSphere. To start, let's first understand what Amazon MWS is and what is it used for.

 

 

Introduction

Amazon Marketplace Web Service (Amazon MWS) is an integrated Web service API that helps Amazon sellers to programmatically exchange data on listings, orders, payments, reports, and more. XML data integration with Amazon enables higher levels of selling automation, which helps sellers grow their business.

 

With Amazon MWS, Amazon listing, order, and payment data can be integrated into existing workflows so that selling on Amazon fits seamlessly with sellers' current business practices.

 

The MWS API

The Amazon MWS API is divided into sections based on functionality. Feed, Finances, Fulfillment, Order API and further information can be found in the Amazon MWS API References.

 

Amazon Feed API: A variety of specialized feed formats are supported to meet a wide range of seller needs. For example, new products can be added to the Amazon catalog by using MWS supported feeds to define new product detail pages on Amazon.com.

 

 

For the feeds API we will follow the the business flow as stated in the above diagram. You can always breakdown the flow based on your business use case. For example you can only submit feed and do not necessarily get a submission report or you would like to get the submissionlist only. 

 

Most of the flow and the functions for the API calls are described in the API guide .We are going to discuss the SubmitFeed API which involves two parts: 

  1. An MD5 hash of the feed content 
  2. the Part of the authentication process that is used for identifying and verifying who is sending a request.

 

In addition to that, the API call requires the request parameters which are mandatory and here is a list of those parameters: Required request parameters 

 

There are some key factors which we need to consider while working with the API's. 

  1. It is case sensitive 
  2. Sequence is important
  3. Be careful with the throttling request and the hourly request quota

 

Testing the API's

You can also test the API request using amazon scratchpad. You will need  awssecretkey ,sellerid, awsaccesskeyid.

https://mws.amazonservices.com/scratchpad/index.html 

 

Example Process Flow

 

Add a set properties shape with the following Process Properties. Note that everything in orange is Process Property.

Signature

AWSAccessKeyId

Action

MWSAuthToken

MarketplaceId

SellerId

Timestamp

 

 

There are six steps in this process: 

 

1. Content-MD5: The Content-MD5 header and ContentMD5Value parameter are used as a message integrity check to verify that the decoded data received is the same data that was initially sent.When you use the SubmitFeed operation, you must create an MD5 hash of the HTTP entity body, and include it in your request. We include the hash in a ContentMD5Value parameter. This lets Amazon Marketplace Web Service (Amazon MWS) compare the MD5 hash you create with the MD5 hash it creates when it receives the feed. Amazon MWS can then determine if the feed submitted for processing is identical to the feed that was received. 

 

import java.util.Properties;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);

//Retrieve a handle to the Logger
DigestInputStream dis = new DigestInputStream(is , MessageDigest.getInstance("MD5"));
byte[] buffer = new byte[8192];
while(dis.read(buffer) > 0);
String md5Content = new String(
org.apache.commons.codec.binary.Base64.encodeBase64(dis.getMessageDigest().digest()),"UTF-8");
props.setProperty("document.dynamic.userdefined.MD5Value", md5Content);
props.setProperty("document.dynamic.userdefined.MD5Content", java.net.URLEncoder.encode(md5Content, "UTF-8"));

dis.close();
dataContext.storeStream(is, props);
}

 

2. Encode Timestamp: 

Use custom scripting to format Timestamp. Note that the date values have to be in ISO 8601 date time format. The valid Timestamp format should be something like this:

2013-09-05T18%3A12%3A21.687Z

Here is the script. Use the data process shape for custom scripting.

 

import java.util.Properties;
import java.io.InputStream;
import java.net.URLEncoder;
String timestamp=''
String EncodedTimestamp=''
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
timestamp= props.getProperty("document.dynamic.userdefined.Timestamp");
EncodedTimestamp = URLEncoder.encode(timestamp,"UTF-8")
props.setProperty("document.dynamic.userdefined.Timestamp", EncodedTimestamp);
dataContext.storeStream(is, props);
}

 

3. CanonicalizedQueryString:  This string is created based on the request body:

AWSAccessKeyId={1}&Action={6}&ContentMD5Value={4}&FeedType={5}&SellerId={2}&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp={3}&Version=2009-01-01

Replace all the parameters with the values based on the properties that you have set.

 

4. Create Signature: Part of the authentication process that is used for identifying and verifying who is sending a request. Please download the attached file which has the signature script.

 

5. CanonicalizedQueryString: After creating the signature, we will create the final query string. It should look like this : 

AWSAccessKeyId={1}&Action={6}&ContentMD5Value={4}&FeedType={5}&SellerId={2}&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp={3}&Version=2009-01-01&Signature={7}

 

6. POST Request: The canonicalizedquerystring will be passed as the replacement variable in the POST request.

 

1 person found this helpful

Attachments

Outcomes