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

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\">;
              <MerchantIdentifier>{{ SellerId }}</MerchantIdentifier>
                   <AmazonOrderID>{{ A }}</AmazonOrderID>
                   <FulfillmentDate>{{ FulfillmentDate }}</FulfillmentDate>
                        <CarrierName>{{ D }}</CarrierName>
                        <ShippingMethod>{{ E }}</ShippingMethod>
                        <ShipperTrackingNumber>{{ C }}</ShipperTrackingNumber>
                        <AmazonOrderItemCode>{{ B }}</AmazonOrderItemCode>

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/">
            <FeedSubmissionId>{{ FeedSubmissionId }}</FeedSubmissionId>
            <SubmittedDate>{{ SubmittedDate }}</SubmittedDate>
        <RequestId>{{ RequestId }}</RequestId>

, 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.

Key differences between Laravel and Symfony 07.09.2019 Key differences between Laravel and Symfony
Which of two frameworks Laravel or Symfony is better to choose for the implementation of the project? For what specific needs this or that framework should be used? Description of the functionality of the frameworks

Implementing a Connection to the Payoneer API 10.09.2019 Implementing a Connection to the Payoneer API
Connection to the Payoneer API payment system. Main connection environments. User’s registration/authorization through the provided link, list of users

Back to the list