2
votes

I have been using amazon mws API for developing a project to find Lowest Priced offers, It works fine with action ListMatchingProducts and GetMatchingProduct but when it comes to GetLowestPricedOffersForASIN, it shows no result in XML output

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

My PHP File Here:

<?php
$param = array();
$param['AWSAccessKeyId']   = ''; 
$param['Action']           = 'GetLowestPricedOffersForASIN';
$param['SellerId']         = ''; 
$param['SignatureMethod']  = 'HmacSHA256';  
$param['SignatureVersion'] = '2'; 
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2011-10-01'; 
$param['MarketplaceId']    = 'ATVPDKIKX0DER'; 
$param['ItemCondition']    = 'used';
$param['ASIN']			   = '0439139600';
$secret = '';
$url = array();
foreach ($param as $key => $val) {

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

sort($url);

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

$sign  = 'GET' . "\n";
$sign .= 'mws.amazonservices.com' . "\n";
$sign .= '/Products/2011-10-01' . "\n";
$sign .= $arr;

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

$link  = "https://mws.amazonservices.com/Products/2011-10-01?";
$link .= $arr . "&Signature=" . $signature;
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
header('Content-type:text/xml');
echo $response;
I can't put AWSAccessKeyID, Secret and SellerID here...
1
I don't think you are using Amazon MWS PHP SDK - Keyur Padalia
yes, sorry, changed that, I have not used SDK, but it's simple cURL request to get the result, for everything else it works perfect, but for GetLowestPricedOffersForASIN, it doesnt shows any result. - Marmik Bhatt
It's really easy to use PHP SDK and will save your lot time - Keyur Padalia
Marmik Bhai if you want to use SDK then i can help you with any API calls as i am using pricechange,reporting,fbainbound/outbound, feeds api - Keyur Padalia
Hi Marmik again i need to see our code to help you. or give me your email address and i can send you some code which might help you - Keyur Padalia

1 Answers

2
votes

Your main problem is, that you use GET instead of POST. This version of your code works:

$param = array();
$param['AWSAccessKeyId']   = ''; 
$param['Action']           = 'GetLowestPricedOffersForASIN';
$param['MarketplaceId']    = 'A1PA6795UKMFR9';
$param['SellerId']         = ''; 
$param['ASIN']             = 'B002BYQIWM'; 
$param['ItemCondition']    = 'New'; 
$param['SignatureMethod']  = 'HmacSHA256';  
$param['SignatureVersion'] = '2'; 
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2011-10-01'; 
$secret = '';
$url = array();
foreach ($param as $key => $val) {
                    $key = str_replace("%7E", "~", rawurlencode($key));
                        $val = str_replace("%7E", "~", rawurlencode($val));
                        $url[] = "{$key}={$val}";
}

sort($url);

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

$sign  = 'POST' . "\n";
$sign .= 'mws.amazonservices.de' . "\n";
$sign .= '/Products/2011-10-01' . "\n";
$sign .= $arr;

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

$signature = urlencode($s64);
$link  = "https://mws.amazonservices.de/Products/2011-10-01";
$arr .= "&Signature=" . $signature;

$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept:'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr); 
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $response;

I have used curl_setopt($ch, CURLOPT_VERBOSE, true); to debug the response from server. Your code did not produced any http body to output, but this http header HTTP/1.1 405 Method Not Allowed. Changing to POST solved your problem.