Меню

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.

Implementation of the structure of the product database from the sql-ex.ru service using Doctrine2 16.09.2019 Implementation of the structure of the product database from the sql-ex.ru service using Doctrine2
Extend your project on a solid basis using the built-in Doctrine2 functionality, try adding your own classes and tables. Description of the product database

Tips for connecting  the ShipStation API serviceto 17.09.2019 Tips for connecting the ShipStation API serviceto
Use the ShipStation API as an aggregator for your service and as a great tool for saving money on sending packages. Description of the service’s features

Back to the list