2

I'm trying to implement an in-house brewed php based way of uploading product to my Amazon marketplace using MWS.

I've trifled through the samples and thought I was on the right track given successful messages and FeedSubmissionID's but that is simply not the case and MWS tells you you've successfully completed a SubmitFeed even though you really didn't.

My question pertains to what exactly my $feed variable should look like when I'm trying to update my inventory. Based off the Amazon MWS found here.

Code

This is a condensed version of SubmitFeedSample.php. My AWS_ACCESS_etc.. is inside my .config.inc.php which is included once at the very beginning. Almost certain all this is good though because I'm getting the success responses.

include_once ('.config.inc.php');

$serviceUrl = "https://mws.amazonservices.com";

$config = array (
  'ServiceURL' => $serviceUrl,
  'ProxyHost' => null,
  'ProxyPort' => -1,
  'MaxErrorRetry' => 3,
);

 $service = new MarketplaceWebService_Client(
     AWS_ACCESS_KEY_ID,
     AWS_SECRET_ACCESS_KEY,
     $config,
     APPLICATION_NAME,
     APPLICATION_VERSION);

$feed = '
<?xml version="1.0" ?>
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>A2EUQ1WTGCTBG2</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
    <MessageID>1</MessageID>
    <OperationType>Update</OperationType>
    <Inventory>
        <SKU>424271</SKU>
        <Quantity>8</Quantity>
    </Inventory>
</Message>
</AmazonEnvelope>
';

$marketplaceIdArray = array("Id" => array('ATVPDKIKX0DER'));

$feedHandle = @fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);

$parameters = array (
  'Merchant' => MERCHANT_ID,
  'MarketplaceIdList' => $marketplaceIdArray,
  'FeedType' => '_POST_INVENTORY_AVAILABILITY_DATA_',
  'FeedContent' => $feedHandle,
  'PurgeAndReplace' => false,
  'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
  //'MWSAuthToken' => '<MWS Auth Token>', // Optional
);

rewind($feedHandle);

$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);

invokeSubmitFeed($service, $request);

@fclose($feedHandle);

  function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
  {
      try {
              $response = $service->submitFeed($request);
                echo ("Service Response\n");
                echo ("=============================================================================\n");

                echo("        SubmitFeedResponse\n");
                if ($response->isSetSubmitFeedResult()) {
                    echo("            SubmitFeedResult\n");
                    $submitFeedResult = $response->getSubmitFeedResult();
                    if ($submitFeedResult->isSetFeedSubmissionInfo()) {
                        echo("                FeedSubmissionInfo\n");
                        $feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
                        if ($feedSubmissionInfo->isSetFeedSubmissionId())
                        {
                            echo("                    FeedSubmissionId\n");
                            echo("                        " . $feedSubmissionInfo->getFeedSubmissionId() . "\n");
                        }
                        if ($feedSubmissionInfo->isSetFeedType())
                        {
                            echo("                    FeedType\n");
                            echo("                        " . $feedSubmissionInfo->getFeedType() . "\n");
                        }
                        if ($feedSubmissionInfo->isSetSubmittedDate())
                        {
                            echo("                    SubmittedDate\n");
                            echo("                        " . $feedSubmissionInfo->getSubmittedDate()->format(DATE_FORMAT) . "\n");
                        }
                        if ($feedSubmissionInfo->isSetFeedProcessingStatus())
                        {
                            echo("                    FeedProcessingStatus\n");
                            echo("                        " . $feedSubmissionInfo->getFeedProcessingStatus() . "\n");
                        }
                        if ($feedSubmissionInfo->isSetStartedProcessingDate())
                        {
                            echo("                    StartedProcessingDate\n");
                            echo("                        " . $feedSubmissionInfo->getStartedProcessingDate()->format(DATE_FORMAT) . "\n");
                        }
                        if ($feedSubmissionInfo->isSetCompletedProcessingDate())
                        {
                            echo("                    CompletedProcessingDate\n");
                            echo("                        " . $feedSubmissionInfo->getCompletedProcessingDate()->format(DATE_FORMAT) . "\n");
                        }
                    }
                }
                if ($response->isSetResponseMetadata()) {
                    echo("            ResponseMetadata\n");
                    $responseMetadata = $response->getResponseMetadata();
                    if ($responseMetadata->isSetRequestId())
                    {
                        echo("                RequestId\n");
                        echo("                    " . $responseMetadata->getRequestId() . "\n");
                    }
                }

                echo("            ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
     } catch (MarketplaceWebService_Exception $ex) {
         echo("Caught Exception: " . $ex->getMessage() . "\n");
         echo("Response Status Code: " . $ex->getStatusCode() . "\n");
         echo("Error Code: " . $ex->getErrorCode() . "\n");
         echo("Error Type: " . $ex->getErrorType() . "\n");
         echo("Request ID: " . $ex->getRequestId() . "\n");
         echo("XML: " . $ex->getXML() . "\n");
         echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
     }
 }

So my $feed variable is the one I have in question. I do have the amzn-envelope.xsd and other .xsd files in the directory with it. What am I doing wrong?

EDIT

I found the solution was in fact my $feed variable in that I did not need the \<\?xml version="1.0" \?> line which was part of my feed.

gh0st
  • 1,653
  • 3
  • 27
  • 59

1 Answers1

3

Your feed validates with the Amazon XSDs which means it is structurally fine, but could still contain logical errors such as there not being a SKU 424271 in your list of products. To get information about logical errors back from Amazon, it is not enough to call SubmitFeed and check its results, because that only tells you that the feed was accepted and put into the processing queue. You also need to wait for that feed to be processed and check the processing results once it is.

how to check the processing state and results of MWS feeds

Please also note that you need to send multiple feeds which are dependent on one another. It is easy for feeds to fail if other feeds haven't been sent (or have failed to process) prior to the current data.

sending multiple dependent MWS feeds to update products

Community
  • 1
  • 1
Hazzit
  • 6,782
  • 1
  • 27
  • 46
  • I used the Amazon Scratchpad and used my FeedSubmissionId to get the processing state and results of the feed I tried to submit. I found that my `$feed` variable did not need the `` line and only needed to begin with the ``. Thank you very much! – gh0st Feb 19 '15 at 19:00