Reputation: 39
Any one know how to update amazon product price using Amazon MWS api.
i have updated my product via MWS Scratchpad using feed submission, but i dont know how to send XML Feed to Amazon.
Upvotes: 1
Views: 3354
Reputation: 11121
Use the Feeds API and if you download one of the client libraries, most of the work is done for you. They currently offer PHP, C#, and Java. Plug in your credentials and then modify the sample code for your use case.
Upvotes: 0
Reputation: 2097
Yaa Amazon is really good with their API documentation Lol.... This might help
$paths = array(
get_include_path(),
realpath(__DIR__ . '/../AmazonAPI/FeedsAPI/src/'),
);
set_include_path(implode(PATH_SEPARATOR, $paths));
unset($paths);
//Includes appropriate config data for Amazon API credentials depending on POS associated with the product
$AWS_ACCESS_KEY_ID = $pos_data['azn_access_key'];
$AWS_SECRET_ACCESS_KEY = $pos_data['azn_secret_access_key'];
$APPLICATION_NAME = $pos_data['azn_app_name'];
$APPLICATION_VERSION = $pos_data['azn_app_version'];
$MERCHANT_ID = $pos_data['azn_merchant_id'];
$MARKETPLACE_ID = $pos_data['azn_marketplace_id'];
$MERCHANT_TOKEN = $pos_data['azn_merchant_token'];
$Service_url = $pos_data['azn_service_url'];
$currency = $pos_data['currency'];
$merchant_token = $MERCHANT_TOKEN;
$config = array(
'ServiceURL' => $Service_url,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3);
$service = new MarketplaceWebService_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $config, $APPLICATION_NAME, $APPLICATION_VERSION);
$feed = <<< EOD
<?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>$merchant_token</MerchantIdentifier>
</Header>
<MessageType>Price</MessageType>
<Message>
<MessageID>1</MessageID>
<Price>
<SKU>$sku</SKU>
<StandardPrice currency="$currency">$new_price</StandardPrice>
</Price>
</Message>
</AmazonEnvelope>
EOD;
echo "\nProduct Price Change Feed for FeedsAPI: \n$feed\n";
$marketplaceIdArray = array("Id" => array($MARKETPLACE_ID));
$feedHandle = @fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$parameters = array(
'Merchant' => $MERCHANT_ID,
'MarketplaceIdList' => $marketplaceIdArray,
'FeedType' => '_POST_PRODUCT_PRICING_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false, //Leave this PurgeAndReplace to false so that it want replace whole product in amazon inventory
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true))
);
rewind($feedHandle);
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
$return_feed = invokeSubmitFeed($service, $request);
function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
{
$DATE_FORMAT = 'Y-m-d';
try
{
$response = $service->submitFeed($request);
echo "\n=============================================================================";
echo "\nSubmitFeedResponse\n";
if($response->isSetSubmitFeedResult())
{
$submitFeedResult = $response->getSubmitFeedResult();
if($submitFeedResult->isSetFeedSubmissionInfo())
{
$feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
if($feedSubmissionInfo->isSetFeedSubmissionId())
{
echo "FeedSubmissionId: " . $feedSubmissionInfo->getFeedSubmissionId() . "\n";
}
if($feedSubmissionInfo->isSetFeedType())
{
echo "FeedType: " . $feedSubmissionInfo->getFeedType() . "\n";
}
if($feedSubmissionInfo->isSetSubmittedDate())
{
echo "SubmittedDate: " . $feedSubmissionInfo->getSubmittedDate()->format($DATE_FORMAT) . "\n";
}
}
echo "=============================================================================\n";
}
if($feedSubmissionInfo->getFeedProcessingStatus() == "_SUBMITTED_")
{
return TRUE;
}
}
catch(MarketplaceWebService_Exception $ex)
{
echo "Caught Exception: " . $ex->getMessage() . "\n";
echo "Response Status Code: " . $ex->getStatusCode() . "\n";
if($ex->getStatusCode() == 503)
{
echo "\n===> WARNING: AMAZON MWS API REQUEST HAS BEEN THROTTLED <===.\n";
}
echo "Error Code: " . $ex->getErrorCode() . "\n";
echo "Error Type: " . $ex->getErrorType() . "\n";
echo "Request ID: " . $ex->getRequestId() . "\n";
echo "XML: " . $ex->getXML() . "\n";
}
}
Upvotes: 6