title: MWS Feeds Update Quantities in php - Amazon
body: <p>it's a few days that I am trying to update the quantity of inventory on Amazon through php and Amazon MWS in php (without using MWS APIs because in my opinion are out of dated)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$param = array();
      $param['AWSAccessKeyId']     = $this-&gt;CHIAVE_ACCESSO;
      $param['Action']             = 'SubmitFeed';
      $param['Merchant']           = $this-&gt;SELLER_ID;
      $param['FeedType']       = '_POST_INVENTORY_AVAILABILITY_DATA_';
      $param['SignatureMethod']    = 'HmacSHA256';
      $param['SignatureVersion']   = '2';
      $param['Timestamp']          = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
      $param['Version']            = '2009-01-01';
      $params['MarketplaceId.Id.1'] = $this-&gt;MARCKETPLACE_IT;
      $params['MarketplaceId.Id.2'] = $this-&gt;MARCKETPLACE_UK;
      $params['MarketplaceId.Id.3'] = $this-&gt;MARCKETPLACE_ES;
      $params['MarketplaceId.Id.4'] = $this-&gt;MARCKETPLACE_DE;
      $params['MarketplaceId.Id.5'] = $this-&gt;MARCKETPLACE_FR;
      $param['PurgeAndReplace']    = 'false';
  
  
      foreach ($param as $key =&gt; $val) {
  
          $key = str_replace("%7E", "~", rawurlencode($key));
          $val = str_replace("%7E", "~", rawurlencode($val));
          $url[] = "{$key}={$val}";
      }
  
      $amazon_feed = '&lt;?xml version="1.0" encoding="utf-8"?&gt;
                      &lt;AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"&gt;
                      &lt;Header&gt;
                      &lt;DocumentVersion&gt;1.01&lt;/DocumentVersion&gt;
                      &lt;MerchantIdentifier&gt;' .$this-&gt;SELLER_ID. '&lt;/MerchantIdentifier&gt;
                      &lt;/Header&gt;
  
                      &lt;MessageType&gt;Inventory&lt;/MessageType&gt;
                      &lt;Message&gt;
                      &lt;MessageID&gt;1&lt;/MessageID&gt;
                      &lt;OperationType&gt;Update&lt;/OperationType&gt;
                      &lt;Inventory&gt;
                      &lt;SKU&gt;'.$sku.'&lt;/SKU&gt;
                      &lt;Quantity&gt;'.$qty.'&lt;/Quantity&gt;
                      &lt;/Inventory&gt;
                      &lt;/Message&gt;
                      &lt;/AmazonEnvelope&gt;';
  
      sort($url);
  
      $arr   = implode('&amp;', $url);
  
      $sign  = 'POST' . "\n";
      $sign .= 'mws.amazonservices.it' . "\n";
      $sign .= '/Feeds/'.$param['Version'].'' . "\n";
      $sign .= $arr;
  
      $signature      = hash_hmac("sha256", $sign, $this-&gt;secretKey, true);
      $httpHeader     =   array();
      $httpHeader[]   =   'Transfer-Encoding: chunked';
      $httpHeader[]   =   'Content-Type: application/xml';
      $httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
      //$httpHeader[]   =   'x-amazon-user-agent: MyScriptName/1.0';
      $httpHeader[]   =   'Expect:';
      $httpHeader[]   =   'Accept:';
  
      $signature      = urlencode(base64_encode($signature));
  
      $link  = "https://mws.amazonservices.it/Feeds/".$param['Version']."?";
      $link .= $arr . "&amp;Signature=" . $signature;
  
      echo $link;
  
      $ch = curl_init($link);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
      $response = curl_exec($ch);
      $info = curl_getinfo($ch);
      $errors=curl_error($ch);
      curl_close($ch);
  
      echo '&lt;pre&gt;';
      print_r($response); //xml response
  </code></pre>
  
  <p>The response is </p>
  
  <p>50691017150_POST_INVENTORY_AVAILABILITY_DATA_2016-12-15T10:00:09+00:00_SUBMITTED_47843855-c5fb-4db9-bc3c-1ccd0aff4169</p>
  
  <p>But When I go on the Amazon Inventory I cannot see any changes. I've tried also to wait some days but nothing changes.
  What I'm doing wrong?</p>
  
  <p>Thanks in advance for help!</p>
  
  <p>Using MWS Scratchpad the error I have is the following</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd"&gt;
  &lt;Header&gt;
      &lt;DocumentVersion&gt;1.02&lt;/DocumentVersion&gt;
      &lt;MerchantIdentifier&gt;A2PDC8GCZHAL2D&lt;/MerchantIdentifier&gt;
  &lt;/Header&gt;
  &lt;MessageType&gt;ProcessingReport&lt;/MessageType&gt;
  &lt;Message&gt;
      &lt;MessageID&gt;1&lt;/MessageID&gt;
      &lt;ProcessingReport&gt;
          &lt;DocumentTransactionID&gt;50691017150&lt;/DocumentTransactionID&gt;
          &lt;StatusCode&gt;Complete&lt;/StatusCode&gt;
          &lt;ProcessingSummary&gt;
              &lt;MessagesProcessed&gt;1&lt;/MessagesProcessed&gt;
              &lt;MessagesSuccessful&gt;0&lt;/MessagesSuccessful&gt;
              &lt;MessagesWithError&gt;1&lt;/MessagesWithError&gt;
              &lt;MessagesWithWarning&gt;0&lt;/MessagesWithWarning&gt;
          &lt;/ProcessingSummary&gt;
          &lt;Result&gt;
              &lt;MessageID&gt;1&lt;/MessageID&gt;
              &lt;ResultCode&gt;Error&lt;/ResultCode&gt;
              &lt;ResultMessageCode&gt;13013&lt;/ResultMessageCode&gt;
              &lt;ResultDescription&gt;This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.it/gp/errorcode/13013&lt;/ResultDescription&gt;
              &lt;AdditionalInfo&gt;
                  &lt;SKU&gt;887235757035&lt;/SKU&gt;
              &lt;/AdditionalInfo&gt;
          &lt;/Result&gt;
      &lt;/ProcessingReport&gt;
  &lt;/Message&gt;
  </code></pre>
  
  <p></p>
  
  <p>but this sku exists in my catalog</p>