Reputation: 14089
I posted this in the Amazon Product Advertising forum but noone is responding, so maybe someone here can help me out.
I'm trying to get a few items to display based on a keyword, so far I have this code and when it runs it says that the request is valid but there are no items returned, I'm trying to use the PHP SoapClient. Can someone please point out what I'm doing wrong?
Here is my code:
<?php
define("ACCESS_KEY",'###');
define("SECRET_KEY",'###');
define("ASSOCIATE_TAG",'###');
$timeStamp = gmdate("Y-m-d\TH:i:s\Z");
$function = "ItemSearch";
$string = $function.$timeStamp;
$signature = base64_encode(hash_hmac("sha256", $string, SECRET_KEY, True));
$client = new SoapClient('http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl');
//var_dump($client->__getFunctions());
$params = array(
"Operation"=>$function,
"AssociateTag"=>ASSOCIATE_TAG,
"Request"=>array("Keywords"=>"book","ResponseGroup"=>"Medium")
);
$header_arr = array();
$header_arr[] = new SoapHeader( 'http://security.amazonaws.com/doc/2007-01-01/', 'AWSAccessKeyId', ACCESS_KEY );
$header_arr[] = new SoapHeader( 'http://security.amazonaws.com/doc/2007-01-01/', 'Timestamp', $timeStamp );
$header_arr[] = new SoapHeader( 'http://security.amazonaws.com/doc/2007-01-01/', 'Signature', $signature );
$client->__setSoapHeaders($header_arr);
$result=$client->__soapCall($function, array($params));
var_dump($result);
?>
And here is the response I get for the keyword book:
object(stdClass)#5 (2) {
["OperationRequest"]=>
object(stdClass)#6 (4) {
["HTTPHeaders"]=>
object(stdClass)#7 (1) {
["Header"]=>
object(stdClass)#8 (2) {
["Name"]=>
string(9) "UserAgent"
["Value"]=>
string(26) "PHP-SOAP/5.3.6-13ubuntu3.3"
}
}
["RequestId"]=>
string(36) "###"
["Arguments"]=>
object(stdClass)#9 (1) {
["Argument"]=>
object(stdClass)#10 (2) {
["Name"]=>
string(7) "Service"
["Value"]=>
string(19) "AWSECommerceService"
}
}
["RequestProcessingTime"]=>
float(0.085933)
}
["Items"]=>
object(stdClass)#11 (1) {
["Request"]=>
object(stdClass)#12 (2) {
["IsValid"]=>
string(4) "True"
["ItemSearchRequest"]=>
object(stdClass)#13 (2) {
["Keywords"]=>
string(4) "book"
["ResponseGroup"]=>
string(6) "Medium"
}
}
}
}
As you can see there is no actual items in the response. From the documentation it seems there should be some sort of TotalResults attribute in the response so I'm absolutely confused why I'm getting something completely different.
Upvotes: 1
Views: 887
Reputation: 14089
So apparently the problem was that you must specify a SearchIndex it doesn't just default to All, or even tell you that it is required it simply doesn't return any results.
So above replace request with:
$params = array(
"Operation"=>$function,
"AssociateTag"=>ASSOCIATE_TAG,
"Request"=>array("SearchIndex"=>"All","Keywords"=>"book","ResponseGroup"=>"Small")
);
Upvotes: 2