Меню

Posting data to Amazon have to be made in a different way

logo
Let's update an order's tracking number for example.
Posting data to Amazon have to be made in a different way

Let's update an order's tracking number for example

At first it should be noticed, that your posting requests have to be signed with the Signature parameter, see Amazon Marketplace Web Service API Connection Guidelines

For sending data to Amazon we need to use the Feed API. All the requests for this API category have to be signed by one more additional signature. The signature will depend on a file we will send in the body of POST-request. Let's assume there is the order with id "A" in the Amazon database. This order contains one product with id "B". We want to set the order's tracking number to "C" for delivery service "D" and delivery method "E".

This way our file will look like this:

<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
    <AmazonEnvelope xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instancet\">;
         <Header>
              <DocumentVersion>1.01</DocumentVersion>
              <MerchantIdentifier>{{ SellerId }}</MerchantIdentifier>
         </Header>
         <MessageType>OrderFulfillment</MessageType>
         <Message>
              <MessageID>1</MessageID>
              <OrderFulfillment>
                   <AmazonOrderID>{{ A }}</AmazonOrderID>
                   <FulfillmentDate>{{ FulfillmentDate }}</FulfillmentDate>
                   <FulfillmentData>
                        <CarrierName>{{ D }}</CarrierName>
                        <ShippingMethod>{{ E }}</ShippingMethod>
                        <ShipperTrackingNumber>{{ C }}</ShipperTrackingNumber>
                   </FulfillmentData>
                   <Item>
                        <AmazonOrderItemCode>{{ B }}</AmazonOrderItemCode>
                         <Quantity>1</Quantity>
                   </Item>
              </OrderFulfillment>
         </Message>
</AmazonEnvelope>

Besides above-mentioned parameters we can see parameters SellerId and FulfillmentDate. SellerId - is unique Amazon user identifier and was considered in part one of the article. FulfillmentDate - is fullfilment date in "ISO 8601" format. Now let's make the signature. We have to encode the file content using md5 method, then encode the result string using base64 method. The result we have to pass as the value of "Content-MD5" header. "D" and "E" parameters may have "USPS" and "USPS First Class" values respectively.

Because the request body contains the file, we have to send "Action" and "FeedType" parameters in a query string, despite the request HTTP-method is POST. Now we have to set "Action" to "SubmitFeed" and "FeedType" to "_POST_ORDER_FULFILLMENT_DATA_". To avoid file sending problems set "Content-Type" header to "text/xml".

Because files can be huge, up to 2Gb, the Amazon service doesn't return the result of a particular file processing with response, but returns the registered feed Id.

A response could contain such text, for example:

<?xml version="1.0"?>
<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
    <SubmitFeedResult>
        <FeedSubmissionInfo>
            <FeedSubmissionId>{{ FeedSubmissionId }}</FeedSubmissionId>
            <FeedType>_POST_ORDER_FULFILLMENT_DATA_</FeedType>
            <SubmittedDate>{{ SubmittedDate }}</SubmittedDate>
            <FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
        </FeedSubmissionInfo>
    </SubmitFeedResult>
    <ResponseMetadata>
        <RequestId>{{ RequestId }}</RequestId>
    </ResponseMetadata>
</SubmitFeedResponse>

, where "FeedSubmissionId" - the feed Id, you can use it later to check the result of file processing, SubmittedDate - feed registration date, RequestId - just response Id, that every Amazon response has.

After some time, but if the file is not huge we can do it by just sending the next request, we will be able to check the feed status, using GET-request with "Action" set to "GetFeedSubmissionResult" and "FeedSubmissionId" with the value of "FeedSubmissionId" from the previous response.

All the rest feeds uploading may be processed in the same way, one just have to know all the needed Ids of the Amazon entities, like above-mentioned order Id "A" and product Id "B". You can get them in Amazon website account section or using API, as was mentioned in part one of the article.

Admitad API Connection Experience 20.09.2019 Admitad API Connection Experience
Admitad is a global affiliate network with a large selection of affiliate programs, high rates, express payments, and many tools.

Mobile applications API 11.10.2019 Mobile applications API
Mobile applications API development tips. It is a common knowledge that websites owners want to provide the same functionality of the sites in the form of mobile applications.

Back to the list