Akash
Akash

Reputation: 91

Amazon MWS - Update product quantity

I am using amazon api for update product's quantity using "_POST_INVENTORY_AVAILABILITY_DATA_" feedtype like,

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

<?xml version="1.0"?>
<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
<SubmitFeedResult>
  <FeedSubmissionInfo>
    <FeedSubmissionId>6791310806</FeedSubmissionId>
    <FeedType>_POST_INVENTORY_AVAILABILITY_DATA_</FeedType>
    <SubmittedDate>2013-03-21T19:48:37+00:00</SubmittedDate>
    <FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
  </FeedSubmissionInfo>
</SubmitFeedResult>
<ResponseMetadata>
  <RequestId>fd07bf18-4f6a-4786-bdf9-9d4db50956d0</RequestId>
</ResponseMetadata>
</SubmitFeedResponse>

but when i try to update 15k or more products at a time by loading products using magento collection quantity not updating in amazon after few hours also. Is it right method or do i need to use any other method?

Can anyone help me?

Thanks in advance.

Upvotes: 3

Views: 4708

Answers (3)

Avadhesh
Avadhesh

Reputation: 1

$feed = '<?xml version="1.0" encoding="utf-8" ?>
            <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
            <Header>
              <DocumentVersion>1.01</DocumentVersion>
              <MerchantIdentifier>AG7AH5X9UOHEC</MerchantIdentifier>
              </Header>
              <MessageType>Inventory</MessageType>
             <Message>
                  <MessageID>1</MessageID>
                  <OperationType>Update</OperationType>
                <Inventory>
                  <SKU>UK-BBD10002</SKU>
                  <Quantity>4</Quantity>
                  <FulfillmentLatency>15</FulfillmentLatency>
                  </Inventory>
             </Message>
            <Message>
                  <MessageID>2</MessageID>
                  <OperationType>Update</OperationType>
                    <Inventory>
                      <SKU>UK-BBD10003</SKU>
                      <Quantity>6</Quantity>
                      <FulfillmentLatency>14</FulfillmentLatency>
                  </Inventory>
              </Message>
            </AmazonEnvelope>';

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

            $param['AWSAccessKeyId']   = Configure::read('AWS_ACCESS_KEY'); 
            $param['Action']           = 'SubmitFeed'; 
            $param['SellerId']         = Configure::read('SELLER_ID'); 
            $param['SignatureMethod']  = Configure::read('SIGNATURE_METHOD');  
            $param['SignatureVersion'] = Configure::read('SIGNATURE_VERSION'); 
            $param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
            $param['Version']          = '2009-01-01'; 
            $param['FeedType']         = $FeedType;              
            $param['FeedContent']      = stream_get_contents($feedHandle);
            $param['ContentMd5']       = base64_encode(md5(stream_get_contents($feedHandle), true));    

            $param['MarketplaceIdList.Id.1'] =  $MARKETPLACE_ID; //FR
            //$param['MarketplaceIdList.Id.2'] =  'A1F83G8C2ARO7P'; //GB


            ksort($param);
            $MARKETPLACE_URL = 'mws.amazonservices.co.uk';  
            $secret = Configure::read('SECRET_KEY');

            $url = array();
            foreach ($param as $key => $val) {

                $key = str_replace("%7E", "~", rawurlencode($key));
                $val = str_replace("%7E", "~", rawurlencode($val));
                $url[] = "{$key}={$val}";
            }

            ksort($url);

            $arr   = implode('&', $url);

            $sign  = 'GET' . "\n";
            $sign .= ''.$MARKETPLACE_URL.'' . "\n";
            $sign .= '/Feeds/2009-01-01' . "\n";
            $sign .= $arr;

            $signature = hash_hmac("sha256", $sign, $secret, true);
            $signature = urlencode(base64_encode($signature));

            $link  = "https://".$MARKETPLACE_URL."/Feeds/2009-01-01?";
            $link .= $arr . "&Signature=" . $signature;

            $httpHeader = array();
            $httpHeader[] = 'Content-Type: application/xml';
            $httpHeader[] = 'Content-MD5: ' .  base64_encode(md5(stream_get_contents($feedHandle), true));
            $httpHeader[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'];
            $httpHeader[] = 'Host: ' . $MARKETPLACE_URL;
            ksort($httpHeader);


            $ch = curl_init($link);
            curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);      
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                     
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
            $response = curl_exec($ch);
            $info = curl_getinfo($ch);
            curl_close($ch);
            @fclose($feedHandle);
            print_r($response);
            exit;

Upvotes: 0

Stephane
Stephane

Reputation: 5078

Quoting Amazon MWS API:

Feed size is limited to 2,147,483,647 bytes (2^31 -1) per feed. If you have a large amount of data to submit, you should submit feeds smaller than the feed size limit by breaking up the data, or submit the feeds over a period of time. One good practice is to submit feeds with a size limit of 30,000 records/items or submit feeds over a period of time, such as every few hours.

Upvotes: 0

Buildtronix
Buildtronix

Reputation: 29

Try Using _POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_ feedtype and send a CSV file (tab delimited) in the body of the https request instead of an XML file. The first line of the csv should be: sku price quantity (separated by tabs) followed by lines containing the values (separated by tabs).

Upvotes: 3

Related Questions