Accessing Amazon Product Advertising API

Updated: 19th October 2011

In this post we will see how to access the Amazon Product Advertising API from PHP. Amazon has recently changed (from 15th Aug ’09) the authentication mechanism for accessing their API which must now be signed with your Amazon keys. Unsigned requests will be rejected by Amazon. Also now Amazon Associate Tag is required in the query (effective from 25th Oct. 2011). Note that the code uses the hash_hmac() hash function which is only available for PHP versions 5.1.2 and above, so the code will not work for versions below that.

A small example

Below is an example to access the Amazon Product Advertising API using the provided class.

    /* Example usage of the Amazon Product Advertising API */
    $obj = new AmazonProductAPI();
        /* Returns a SimpleXML object */
         $result = $obj->searchProducts("X-Men Origins",
    catch(Exception $e)
        echo $e->getMessage();

You can convert the returned xml to json with the following line.

$result = json_encode($result);

The API access class

Given below is the implementation of the class to access the Amazon Product Advertising API. Comments have been removed for brevity, but are included in the source download. Note that only a few access operations are implemented in the class: ItemLookup, ItemSearch; there are more available in the API, a complete list can be found here. It’s just a simple matter of changing some parameters to implement others.

require_once 'aws_signed_request.php';
class AmazonProductAPI
    private $public_key     = "YOUR AMAZON ACCESS KEY ID";
    private $private_key    = "YOUR AMAZON SECRET KEY";
    /* 'Associate Tag' now required, effective from 25th Oct. 2011 */
    private $associate_tag  = "YOUR AMAZON ASSOCIATE TAG";
    const MUSIC = "Music";
    const DVD   = "DVD";
    const GAMES = "VideoGames";
    private function verifyXmlResponse($response)
        if ($response === False)
            throw new Exception("Could not connect to Amazon");
            if (isset($response->Items->Item->ItemAttributes->Title))
                return ($response);
                throw new Exception("Invalid xml response.");
    private function queryAmazon($parameters)
        return aws_signed_request("com",
    public function searchProducts($search,$category,$searchType="UPC")
        $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD");
        $allowedCategories = array("Music", "DVD", "VideoGames");
            case "UPC" :
                $parameters = array("Operation"     => "ItemLookup",
                                    "ItemId"        => $search,
                                    "SearchIndex"   => $category,
                                    "IdType"        => "UPC",
                                    "ResponseGroup" => "Medium");
            case "TITLE" :
                $parameters = array("Operation"     => "ItemSearch",
                                    "Title"         => $search,
                                    "SearchIndex"   => $category,
                                    "ResponseGroup" => "Medium");
        $xml_response = $this->queryAmazon($parameters);
        return $this->verifyXmlResponse($xml_response);
    public function getItemByUpc($upc_code, $product_type)
        $parameters = array("Operation"     => "ItemLookup",
                            "ItemId"        => $upc_code,
                            "SearchIndex"   => $product_type,
                            "IdType"        => "UPC",
                            "ResponseGroup" => "Medium");
        $xml_response = $this->queryAmazon($parameters);
        return $this->verifyXmlResponse($xml_response);
    public function getItemByAsin($asin_code)
        $parameters = array("Operation"     => "ItemLookup",
                            "ItemId"        => $asin_code,
                            "ResponseGroup" => "Medium");
        $xml_response = $this->queryAmazon($parameters);
        return $this->verifyXmlResponse($xml_response);
    public function getItemByKeyword($keyword, $product_type)
        $parameters = array("Operation"   => "ItemSearch",
                            "Keywords"    => $keyword,
                            "SearchIndex" => $product_type);
        $xml_response = $this->queryAmazon($parameters);
        return $this->verifyXmlResponse($xml_response);

Amazon signed request

The above class uses the ‘aws_signed_request’ function to generate the new request signature. Original code is by Ulrich Mierendorff, modified here to use cURL.

function  aws_signed_request($region,
    $method = "GET";
    $host = "ecs.amazonaws.".$region;
    $uri = "/onca/xml";
    $params["Service"]          = "AWSECommerceService";
    $params["AWSAccessKeyId"]   = $public_key;
    $params["AssociateTag"]     = $associate_tag;
    $params["Timestamp"]        = gmdate("Y-m-d\TH:i:s\Z");
    $params["Version"]          = "2009-03-31";
    /* The params need to be sorted by the key, as Amazon does this at
      their end and then generates the hash of the same. If the params
      are not in order then the generated hash will be different from
      Amazon thus failing the authentication process.
    $canonicalized_query = array();
    foreach ($params as $param=>$value)
        $param = str_replace("%7E", "~", rawurlencode($param));
        $value = str_replace("%7E", "~", rawurlencode($value));
        $canonicalized_query[] = $param."=".$value;
    $canonicalized_query = implode("&", $canonicalized_query);
    $string_to_sign = $method."\n".$host."\n".$uri."\n".
    /* calculate the signature using HMAC, SHA256 and base64-encoding */
    $signature = base64_encode(hash_hmac("sha256", 
                                  $string_to_sign, $private_key, True));
    /* encode the signature for the request */
    $signature = str_replace("%7E", "~", rawurlencode($signature));
    /* create request */
    $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
    /* I prefer using CURL */
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$request);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $xml_response = curl_exec($ch);
    if ($xml_response === False)
        return False;
        /* parse XML and return a SimpleXML object, if you would
           rather like raw xml then just return the $xml_response.
        $parsed_xml = @simplexml_load_string($xml_response);
        return ($parsed_xml === False) ? False : $parsed_xml;
Download Source
Downloads : 13187 / File size : 5 kB

This site is a digital habitat of Sameer Borate, a freelance web developer working in PHP, MySQL and WordPress. I also provide web scraping services, website design and development and integration of various Open Source API's. Contact me at metapix[at] for any new project requirements and price quotes.

133 Responses


Steven Klotz

August 22nd, 2009 at 3:59 pm

Thanks, this was just what I needed to get started.



August 28th, 2009 at 5:13 pm

Thanks for sharing your source. Very helpfull!



September 4th, 2009 at 7:47 am

Thank for share. Great source.



September 20th, 2009 at 11:56 pm

Thanks for helps me a lot..



September 21st, 2009 at 1:22 pm

Very helpful code! Thanks!


cd smith

September 30th, 2009 at 7:00 pm

How do you change the code to show reviews? I been trying to modify to do that, I am missing something.


September 30th, 2009 at 9:08 pm

You need to change the response group to ‘Large’ or ‘Medium’ in the following lines:

“ResponseGroup” => “Medium”);

To find out what elements are returned by the various groups, you can go here:


cd smith

September 30th, 2009 at 9:58 pm

I tried that earlier unsuccessfully.

Here is what I did:


case “TITLE” : $parameters = array(“Operation” => “ItemSearch”,
“Title” => $search,
“SearchIndex” => $category,
“ResponseGroup” => “Large”);



echo “Sales Rank : {$result->Items->Item->SalesRank}”;

echo “ASIN : {$result->Items->Item->ASIN}”;
echo “Sales Detail : {$result->Items->Item->EditorialReviews->EditorialReview}”;

echo “Items->Item->LargeImage->URL . “\” />”;

Where did go wrong? Thanks.


October 1st, 2009 at 12:42 am

You need to do the following using the ‘Large’ response group:

echo $result->Items->Item->CustomerReviews->Review[0]->Content;

echo $result->Items->Item->EditorialReviews->EditorialReview[0]->Content;


cd smith

October 1st, 2009 at 5:10 am

That worked! But I have one last question:

How did you know the proper way to format the echo string to display the data?

I cannot find that information in the documentation.

For instance, there is a “Source” tag in the XML but if I add that in the string, nothing displays.

Ex: $result->Items->Item->EditorialReviews->EditorialReview[0]->Source->Content;


October 1st, 2009 at 5:32 am

Just print the $result using


and view the source, this will display the serialized data from which you can get the node names; or in the ‘aws_signed_request.php’ file, after the line

$xml_response = curl_exec($ch);

add the following lines:


This will display the actual XML returned by Amazon.


cd smith

October 1st, 2009 at 8:11 am

Thanks again..The print_r statement browser display was too jumbled to read it clearly but when I viewed the “source” of the webpage, everything became very understandable.

[CustomerReviews] => SimpleXMLElement Object
[AverageRating] => 4.5
[TotalReviews] => 31
[TotalReviewPages] => 7
[Review] => Array
[0] => SimpleXMLElement Object
[ASIN] => B000000ZML
[Rating] => 5
[HelpfulVotes] => 0
[CustomerId] => A12GGA1DTETD2H
[Reviewer] => SimpleXMLElement Object

All I need to do now is figure out how to display the “Add To Cart” button.

Thanks again..


Helen Hunt

October 7th, 2009 at 4:45 am

Thanks for the awesome piece of code that has made my affiliate programme much better.

I was struggling with the new signature and timestamp requirements until I saw your solution.

Keep it up and thanks for sharing. Lovely blog BTW :)



October 12th, 2009 at 1:58 am

Finally a script that work!! Thnx man!!


Jim Keller

October 24th, 2009 at 12:32 pm

I was using a foreach loop to generate the query string rather than implode() as above, and noticed that the request was failing with an invalid signature because I had forgotten to rtrim() the last ampersand from the query string.

Thanks for the code – this was a huge help, and things seem to be working now.


Jonathan Montgomery

October 26th, 2009 at 3:32 pm

This returns an error message “The request must contain the parameter Signature” every time. Any idea why?


Anup Khandelwal

October 26th, 2009 at 10:53 pm

Thanks for sharing your script. I need small help from you. I am working on magazine price comparison site, wherein on comparison page i need to display magazine of amazon. Can i cache amazon records on my db?


October 26th, 2009 at 10:59 pm

Anup, you are not quite clear on your question, but you can cache any Amazon results in your db for latter access, but I’m not sure how long the cache should remain valid. If Amazon updates their db then your cache can go stale.



October 29th, 2009 at 12:29 pm

Hay man thanks a lot, very useful code…. thanks again :-)


Anup Khandelwal

November 24th, 2009 at 11:37 pm

Hi Sameer,
I am successfully able to retrieve magazines from the class you developed. Thank you so much.

But i facing one problem which is:

I want to retrieve magazine name ‘TIME’. But i am getting output of all magazine result which match Magazine Title ‘TIME’. I need exact match result for Magazine Title. Can you please suggest me solution for same.

Code Snippet:
$obj = new AmazonProductAPI();
$result = $obj->searchProducts(“TIME”, AmazonProductAPI::MAGAZINE, “TITLE”);



November 25th, 2009 at 12:12 am

Try adding an extra parameter, like the ‘Publisher’ name in the query. The publisher for ‘Time’ magazine is ‘Time Direct Ventures’, so you can add that to the ‘Title’ parameter. So the code in the class would look like this:


case "TITLE" :
$parameters = array("Operation" => "ItemSearch",
"Title" => $search,
"Publisher" => "Time Direct Ventures",
"SearchIndex" => $category,
"ResponseGroup" => "Large");

Parameter which you can use are given here:



December 15th, 2009 at 5:40 am

Hello Sameer,

I am trying to get categories of Books to show on my page using amazon api. Code that you provide is good. i m getting perticular book search result but i want to show books sub categories. can u please tell me what changes i have to do in same code?


December 15th, 2009 at 6:35 am

You need to search with the ‘BrowseNode’ parameter. For example in the ‘amazon_api_class.php’ file you can change the following code:

case "TITLE" : $parameters = array("Operation" => "ItemSearch",
"Title" => $search,
"SearchIndex" => $category,
"ResponseGroup" => "Large");


case "TITLE" : $parameters = array("Operation" => "ItemSearch",
"BrowseNode" => 283155,
"SearchIndex" => "Books",
"ResponseGroup" => "BrowseNodes");

This will return all the subcategories of ‘Books’, with the names and their BrowseNodes.
The BrowseNode ‘283155’ is that of Books.

Note: When using BrowseNodes, replace the following line:

return $this->verifyXmlResponse($xml_response);


return $xml_response;

Now you can search for a particular category by using its BrowseNode and some other search criteria, like say keyword.

case "TITLE" : $parameters = array("Operation" => "ItemSearch",
"BrowseNode" => 75,
"Keywords" => $search,
"SearchIndex" => "Books",
"ResponseGroup" => "Large");

The BrowseNode given above (75) is for the ‘Science’ category.

You can find a list of BrowseNodes here:


Chandra Mouli

December 16th, 2009 at 8:51 pm

This is Chandra Mouli. Tanikonda.Please let me know how to connect to the Amazon product api from our applicatin.Thanks in advance..

Chandra Mouli Tanikonda



December 19th, 2009 at 3:39 am

Thanks a lot Sameer. Now it is working fine



January 4th, 2010 at 12:50 pm

Thanks a lot for this script !! Finally something understandable and WORKING !!

Do you also have something for creating and managing their distant basket ?



January 5th, 2010 at 3:40 am

Hello Sameer,

Can you please tell me how i can integrate remote shopping cart provided by Amazon API? I am trying CartCreate operation but it is not working. Can you please tell me details?



Aaron Mc Adam

March 2nd, 2010 at 9:37 pm

Hey Sameer, thanks very much for your class, I’m trying to figure out a good way of caching the results, as only 10 results are returned for each request. I think I have an idea how to do it but I was wondering if you had already fixed this problem?


March 2nd, 2010 at 9:56 pm

I’ve not yet implemented a cache yet, I’d be enlightened to know about your idea.



March 15th, 2010 at 4:02 pm

Firstly thanks very mch for the code – works great!!

Just in case anyone else is getting the error:

“The request must contain the parameter Signature.”

– make sure you haven’t cut and pasted the code from this webpage (better to download at the link above). If you cut and paste from the page this line is corrupted:

$request = “http://”.$host.$uri.”?”.$canonicalized_query.”

should be:

$request = “http://”.$host.$uri.”?”.$canonicalized_query.”&Signature=”.$signature;

i.e no newlines in it!

Tookk me sometime to work out the problem :(



March 25th, 2010 at 10:21 pm

Hi Sameer,

First of all, thanks a million! This code works really well and I was able to integrate these into my wordpress theme’s functions.php and it is currently working fine.

However, the issue I am having is that when I try to call the search function (along the lines of example.php) at 2 different places on my page, it doesn’t work and also breaks the flow, or execution of the PHP code for my page. I’m not really sure why this is happening, but it might be related to a clashing of variable/objects?

I don’t know if this makes much sense, but if you have any idea why this might be happening, I would greatly appreciate your thoughts. Thanks a ton.



March 25th, 2010 at 10:33 pm

Make sure you are using PHP 5 or greater for your WordPress installation, which probably you would be. Can you be more specific regarding the error your are getting. I don’t think Variable/Object clashes are the reason.



March 25th, 2010 at 11:12 pm

Hi Sameer,

Scratch that. I just made a separate php file with everything combined and included it in the header using require_once. That works fine. Including the code in functions.php just seemed like asking for trouble. Not quite sure why it wasn’t working, but this way it works perfectly!

Thanks again for putting this up. I’m surprised how hard it was to find such an example on the Amazon API, considering that it is quite commonly used.




March 26th, 2010 at 7:17 am

Hi Sameer,

Sorry for the barrage of comments/questions =). One last question I had. I tried looking this up but I couldn’t find anything for sure. Is there a way to query Amazon just for 1 or two items instead of the default 10? I’m wondering if that might help with pageloading speed? I’m worried that if I have 4-5 individual modules searching for a specific keyword/item it might drastically increase page-load times. Do you have any thoughts/comments on this?

Thanks a ton.



March 26th, 2010 at 7:29 am

As far as I know Amazon returns a default of 10 items per page. You cannot request for lesser items. To reduce load on your server you can request the ‘Small’ response group, which by the way is the default.



March 26th, 2010 at 9:19 am

Thanks for the quick reply Sameer. Unfortunately I want to display the Average rating for each product, and I believe that this is only possible with the Large Response group. I’ll run some tests to see how much it is affecting page load speeds. Perhaps the best solution would be to use a caching solution like WP-Super Cache, to enhance page load times.




April 22nd, 2010 at 3:14 am

thanks so much !
The first php script which works !



April 24th, 2010 at 2:32 am

Great code! Works right out of the box. Thanks for posting this ;-)



May 13th, 2010 at 8:08 am

Well I must be the only one that cant get it too work :( ive put my keys in and left the script exactly as it is, and I get a few images of a wolverine DVD with stills, a description and loads of XML coding on the screen :(

been trying for months to get amazon api working, this is the closet though, HELP


May 13th, 2010 at 8:30 am

Well james you do get the xml output if you us the ‘Example.php’ file. comment out the following line in ‘Example.php’.


You can access various details using the object notation. For example to access the Sales rank use the following code:


Same with the other item properties.



May 13th, 2010 at 8:45 am

oooh! im so dull! thanks sameer, can see my IRON MAN dvd!

but how do I get people to buy it! i.e basket button? and where are the parameters to show other stuff like cost?

cant believe it works!


May 13th, 2010 at 8:52 am

James the code I’ve given does not implement all the API functions. There are a lot. But all of them use the same calling conventions. A complete list of functions to create a cart and others can be found here:



May 13th, 2010 at 8:57 am

thanks sameer, you have been most helpful, I have no idea how to search for latest releases or anything, does that code go into example.php? I typed iron man 2 into example.php and I got 1 dvd result back, how would I get top ten?

last queston I promise! ;)


May 13th, 2010 at 9:15 pm

The API by default returns the top 10 results. You can for example access the sales rank of the 9th item using the following:


(The index starts at ‘0’)

To look at other item properties do a


and then view the source of the page.



May 14th, 2010 at 1:24 am

Mine only ever returns 1 result, I have no idea how to get the latest top ten xbox games to show for example. I guess this is too complicated for me :(



May 19th, 2010 at 1:31 am

Thanks for the method for getting the top selling items – I’m amazed it’s not a function in the API but there you go.


Amir Shevat

May 20th, 2010 at 4:03 am

Great script.

If you add a pre tag before the print_r it will format your result in a nicer way:

echo “”;
echo “”;




May 24th, 2010 at 1:21 am

So how do I list top ten latest DVD`s? I dont get this at all :(



May 27th, 2010 at 4:15 am

this is wonderful tutorial .. i read it 3 times and get a fantastic results and sure i put a
copy of this lesson on my site here



June 1st, 2010 at 4:26 pm

Thank you very much This is what I was looking



June 3rd, 2010 at 1:02 am

glad you all got it working :(



June 10th, 2010 at 10:19 pm

Thanks for the code, i was searching for this kind of the code, its working fine. But i have a question, I am getting the result for SearchIndex as “Book” an Keywirds as a”audio recording, it giving the result fine, it shows that there are [TotalResults] => 6795 [TotalPages] => 680 but i am able to display only 10 items out of that, how do i get remaining items?
thanks in Advance



June 11th, 2010 at 9:43 pm

You will need to add the ‘ItemPage’ parameter in the given class. For example :

$parameters = array(“Operation” => “ItemSearch”,
“Keywords” => $keyword,
“ItemPage” => 2,
“SearchIndex” => $product_type);

Check the Amazon API documentation for more info.



June 13th, 2010 at 4:45 am

And where do i add Associate ID in the request for the rewards



June 24th, 2010 at 10:50 pm

Hi Can anyone tell me how to dislplay the reviews and how to sort them in decending order This is the code of amazon

function theItemWindow() {
global $Result;
global $bn;

echo ”;
if ($bn != FIRST_TIME) {
foreach ($Result[‘MultiOperationResponse’][‘ItemSearchResponse’][‘Items’][0][‘Item’] as $item) {
if (isset($item[‘SmallImage’][‘URL’])) {

//$res= $item[“CustomerReviews”][“TotalReviews”];
//echo “$res”;
// $reviews = $item[“”]
} else {

$title = ‘‘. $item[“ItemAttributes”][ “Title”].’‘;
if (is_int($rowcount/5)) echo ”;

echo ”.$title.”.$image.”.$reviews.”;

else {
echo ‘Choose a category on the left';

echo ”;




June 25th, 2010 at 5:43 am

I get a search result which has 18 items. I choose to list the products which has only the Offers->Offer->OfferListing->OfferListingId

Now even though the result set has 2 pages, in the first page only 3 products get displayed because of the above criteria.

Is there a way to tell amazon to fetch records which has only the Offers->Offer->OfferListing->OfferListingId so that the Items->TotalResults and Items->TotalPages are correct?

thanks in advance



July 6th, 2010 at 12:36 am

Hi Sameer

It is a great code, Thanks for publishing it.
I am using the same example after downloading it. But i am not getting any response.

I am getting “Could not connect to Amazon” error. I had tried and checked that the response is blank.

Can you please help me.

Thanks in advance.



July 16th, 2010 at 12:29 pm

I am querying Amazon trying to get seller’s listing using the following parameters:

$parameters = array(“Operation” => “SellerListingSearch”,
“ListingPage” => 1,
“SellerId” => “XXXXXXXXXXX”,
“BrowseNode” => 266239,
“SearchIndex” => “Marketplace”,
“ResponseGroup” => “SellerListing”

Although I can successfully get a list of 2400 books at, I am unable yet to find their exact browse nodes nor the BrowseNode parameter work for any value.

I get same number of books every time no matter what BrowseNode is sent in parameter. Please tell me how I can get categorized items under a BrowseNode against a seller id?

Thanks in advance!!!



July 16th, 2010 at 11:25 pm


Excellent code and very easy to impliment. I have a similar question to poster #52.

For your getItemByKeyword(), function, if I type in for example, biology, and make the search Index “books”, I get about 6000 items. I would like to print the picture of say the first 200. How would I modify your code to do that?


Julio Montoya

August 3rd, 2010 at 1:20 pm

Hello, which is the license of the code? If this is GPLv3?


August 4th, 2010 at 12:01 am

Hello Julio!
I’ve not licensed it in any way. You are free to do whatever you like with the code.



August 4th, 2010 at 12:20 am

This api is basically a referal program. i mean i will get paid about 15% of the books sold through my refrence. Actually i am bit worried about this and i don’t know that which link should i use to make that thing possible. My motive is to send user to amazon site from my site by clicking a book so that i can get about 15% commision of the purchase. Please guide me what should i do…………
Thanks for posting such a nice tutorial…..Even amazon documentation is not that much helpful



August 10th, 2010 at 4:32 am

Hi Sameer,
The code is working fine if i query amazon with 10 digit ISBN code. but if i query the amazon with 13 digit ISBN number then it gives excetion error.
Have look on my function :-
public function getItemByAsin($asin_code)
$parameters = array(“Operation” => “ItemLookup”,
“ItemId” => $asin_code,
“ResponseGroup” => “Medium”);

$xml_response = $this->queryAmazon($parameters);

return $this->verifyXmlResponse($xml_response);

$isbn_number = 978-0979181511; //(gives error)
//$isbn_number = 0979181511; // (runs without error)

$result1 = $obj->getItemByAsin($isbn_number);

Both the ISBN number belongs to same book. even then they are showing error.. please check and reslove this issue…….



August 16th, 2012 at 12:27 pm

This is what I like the most: Updated: 19th October 2011 Appreciated :D



August 18th, 2012 at 12:03 pm

Hi Guys! I had my site working fine implementing this code but all of a sudden everything stopped working. I noticed that the new documentation requires the “amazon associates tag,” in which I updated but still no response coming back. I re-checked my amazon access key, it is valid and active. The only thing I can think about that might have messed things up is the recent change on GoDaddy servers to PHP 5.3, which may have broken some things. Can anyone help please?



September 9th, 2012 at 11:23 pm

Sham, I am also facing the same problem as u r. everything stop working anyone help to solve this problem.


September 9th, 2012 at 11:45 pm


I’ve just tested the above code and it is working fine. To debug add the following line in the ‘aws_signed_request.php’ file after ‘$xml_response = curl_exec($ch);’

So it should look like this:

$xml_response = curl_exec($ch);
echo $xml_response;

This will surely help you pinpoint any errors Amazon is throwing and will help you resolve the issue.



September 11th, 2012 at 5:20 pm

How do I make it so it doesn’t return anything on my screen expect for what I echo. I’m trying to return just the ASIN but its returning every bit of information there is about the item I’m looking up


girish joshi

September 20th, 2012 at 3:33 am

sir i want to convert amazon older api into amazon mws api so plz if there is any help regarding that so please provide me.



October 7th, 2012 at 11:33 pm

Hi to all.,

The code working super it saved my time lot and one doubt on this code i need to display the reviews like 4.5 currently it shows the all reviews URL i just want to display the rating only please any one help to me..

Thanks in advance
Thanks & Regards


How to make a music (web) mashup – Muskblog

October 21st, 2012 at 1:54 pm

[…] the first two I worked with and recommend because they offer lots of information and images is Amazon Product API and Both have PHP code available showing you how to do basic and advanced […]


Murali M

October 21st, 2012 at 6:52 pm


Can you pls send me an email, i would like your help to an AMAZON API site. My website stopped working with the new signing in



October 26th, 2012 at 4:44 am

Sir i am not getting any error and also no output what to do….can anyone help me plz



October 27th, 2012 at 1:35 am

U guys always said it display 10 products on the screen. Using the Example.php file, managed to get loads of XML coding but with only 1 image at the bottom. Does anyone has the code to display the 10 products?




October 27th, 2012 at 11:26 am

I modified and extended this class some over the years. I recently put it in GitHub too with the rest of my web mashup PHP code.



November 25th, 2012 at 5:49 am

Hi Sameer,

Do we need to pay amazon every time we are querying their database using your script?



November 25th, 2012 at 6:41 am

Nope. These are free services, however above a certain limit they will throttle your requests.



November 29th, 2012 at 10:02 am

THanks you so much sir!

you just saved a poor life.


Php Developer

December 19th, 2012 at 5:44 am

Hello I am using Amazon Api for display songs of an artist. I am using

case “TITLE” : $parameters = array(“Operation” => “ItemSearch”,
“Title” => $search,
“SearchIndex” => $category,
“ResponseGroup” => “Medium”);

and send parameters as

$params[“Service”] = “AWSECommerceService”;
$params[“AWSAccessKeyId”] = $public_key;
$params[“AssociateTag”] = $associate_tag;
$params[“Timestamp”] = gmdate(“Y-m-d\TH:i:s\Z”);
$params[“Version”] = “2009-03-31″;
$params[“Sort”] = “artistrank”;

But the results I am getting are not in correct order
Means sort is not working.

My Results should be like this URL:

But I am getting different results as :

Please tell me how can I get top 10 results as given url




December 25th, 2012 at 1:03 pm

Hi all and thank You for sharing your code. I don’t understand Amazon API very nice. I’m trying lo learn it :-). How could I search for toys. For examples, all LEGO products in Toys category? Im’m trying to modify your code but I receive dvd.

Thank You again for sharing.
King regards



December 27th, 2012 at 7:41 am

Just another question. How to “point to” ??? I’ve found a $region variable but changing it, I receive an error :-(

Thank You again


CD Collection Browser Mashup is basically done – Muskblog

January 20th, 2013 at 5:33 pm

[…] Amazon API by Sameer Borate […]



February 6th, 2013 at 2:25 am

Great library man, you’re rock! thanks :D



February 8th, 2013 at 4:41 pm

Hi Sameer,
Thanks very much for this code.. I just try it..

But, I am still confusing searching to solve my problem,

The code of (on the example.php):

echo “Sales Rank : {$result->Items->Item->SalesRank}”;
echo “ASIN : {$result->Items->Item->ASIN}”;
echo “Items->Item->MediumImage->URL . “\” />”;

it just show 1 product.. As people said that it show 10 products, but not on me.

Just try to add “array” code, but I think I was wrong.. :D

Would you suggest me to correct which code I should change and how..

I downloaded the file on the zipped above..

Thanks for your help..

Have a great day Sameer.. ^_^



February 12th, 2013 at 6:38 am

Hi Sameer,

Can you please help me in this regard. I need to get the top 100 best sellers of tablets from Amazon. I have given this request and its giving me the 10 best seller products. I gave page number in the request and its showing the same 10 results. How to get this 100 products using pagination. My current request is like below. TAG]&BrowseNodeId=565108&Condition=Large&ItemPage=3&Operation=BrowseNodeLookup&ResponseGroup=TopSellers&Service=AWSECommerceService&Timestamp=2013-02-12T13%3A10%3A01.000Z&Version=2010-11-01&Signature=[Signature]

Can you please help me to get the 100 best seller products? Thanks in advance.


PHP Kool Aid – Muskblog

February 17th, 2013 at 1:13 pm

[…] on keeping on. Although a lot of my work isn’t readily apparent, I’ve gotten both an Amazon API and the API working. I’ve also discovered that making a lot of requests to these […]


Second Cover Gallery Proof of Concept – Muskblog

March 10th, 2013 at 1:55 pm

[…] ones, but fetching images from Flickr is easy, fetching information and images form Last.FM and Amazon requires private and public […]



March 28th, 2013 at 7:07 am

Hi Sameer,
I want to pull book image from amazon and display on my webpage.
any body help me here please
thankx a lot


Amazon Product API Examples in PHP | This is my web site

April 12th, 2013 at 11:54 pm

[…] did find a useful and well documented example from CodeDiesel called Accessing Amazon Product Advertising API and it gets the job done with very little configuration – all you have to do is change three […]



April 16th, 2013 at 10:07 pm

Sir, i am try to implement the api of amazon to fetch the result from amazon site.

but i am not going in right direction, can you please tell me the step by step procedure to implement this code and please send me detail of code to used in my site.

Thank You



How to access more than 10 item's detail in Amazon api using php? - How-To Video

April 24th, 2013 at 3:31 am

[…] am working with amazon api and have used code from online sources…. i would like to get more than 10 product’s detail when i make a search query using amazon […]



May 14th, 2014 at 6:08 am

Excellent post, and much appreciated. The Amazon help resources are not great for this, and your example is both a great way to implement as well as learn the resource.



May 14th, 2014 at 3:48 pm

Is this api still valid in 2014 or is the new Amazon product api mws? I want to create a WordPress shopping cart site (ex. getshopped) where physical products are sold and compare the cart’s prices to Amazon’s product api. Could you help me figure out the best way to do this?


inamullah buksh

May 20th, 2014 at 6:26 am

sir this example i am run but the output is blank but i am add the access key or privae key but the output is blank so please help me



June 9th, 2014 at 10:28 am

hi i getting fatal error on this code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$xml_response = curl_exec($ch);

wht should i do?


tankless water heater

June 19th, 2014 at 6:08 pm

how i can generated rating and total reviews??



July 4th, 2014 at 9:27 am

Just wanted to say thank you for this resource! Just the start I needed to figure it out.


Simulasi Hitung KPR

July 12th, 2014 at 1:36 am

Not work, I get error like this :

Invalid xml response.
Notice: Undefined variable: result in C:\xampp\htdocs\web14\Example.php on line 19

Notice: Undefined variable: result in C:\xampp\htdocs\web14\Example.php on line 21

Notice: Trying to get property of non-object in C:\xampp\htdocs\web14\Example.php on line 21

Notice: Trying to get property of non-object in C:\xampp\htdocs\web14\Example.php on line 21

Notice: Trying to get property of non-object in C:\xampp\htdocs\web14\Example.php on line 21



September 19th, 2014 at 8:53 am

Could you provide simple php code to display amazon bestseller



September 22nd, 2014 at 3:08 pm

Amz. API Documentation is really bad. But this made my day, thank you!



September 23rd, 2014 at 12:54 am

Which variabel must be change to search for ALL category? I try add const ALL = “All”; in api class but error : Invalid xml response.

How i can search for all category?




September 25th, 2014 at 8:22 am

Not work, there’s error like this :

Notice: Use of undefined constant B0067HQL30 – assumed ‘B0067HQL30′ in C:\xampp\htdocs\web20\index.php on line 8
Invalid xml response.

Kalkulator Hitung Angsuran KPR


saba Umar

October 14th, 2014 at 4:49 am

Very Good Post and the the examples are added so helpful. here i went to share an other good post related to Amazon MWS It also be beneficial for.



October 23rd, 2014 at 6:22 am

Great service and works fine even in 2014 :)

However, and as many others stated over the years in the comments – How exactly do you access the returned array?

$request->items->item is only a single item, However for some reason $request->items->item[3] is the 3rd item,

It’s like ` $request->items->item ` is an array, but it points to the first element. Any thoughts?



October 26th, 2014 at 11:37 am

When I ran the ‘Exanple.php’ I received an xml file output. What do I do with it. When unitTest\AmazonApiTest.php was run I got blank page and I could not find Framework.php as it says on the file ‘require_once ‘PHPUnit/Framework.php’

How do I implement it on wordpress? Thanks!


October 30th, 2014 at 9:25 pm

@Patrick, $request is an SimpleXMLElement Object, so you will need to iterate like the following example:

foreach($request->Items->Item as $i)
$d = $i->Offers->Offer->OfferListing->PercentageSaved;
echo $k++ . ” ” . $d . “\n”;



November 25th, 2014 at 11:58 am

How to get availability status of an item whether available or not as field is not there regarding that..Please help…


November 26th, 2014 at 12:32 am



November 28th, 2014 at 10:26 am

It’s working fine. How to convert this php xml to json?


November 29th, 2014 at 5:22 am

use the following:

$result = json_encode($result);



November 30th, 2014 at 5:08 am

Thanks man for can we get next 10 products subsequently with script one by one after first 10 products..I modified the code a bit but got an error after that.Can you please help regarding that?


November 30th, 2014 at 6:01 am

You will need to add the ‘ItemPage ‘ parameter in the ‘searchProducts’ function. Check the following link for additional details regarding the parameter.



November 30th, 2014 at 6:21 am

I added that like below

case “TITLE” : $parameters = array(“Operation” => “ItemSearch”,
“Title” => $search,
“SearchIndex” => $category,
“ResponseGroup” => “Medium”);


secondly i use like this

for ($i=1;$i “ItemSearch”,
“Title” => $search,
“SearchIndex” => $category,
“ResponseGroup” => “Medium”);

// }

both throws error

when i give value as 10,it works but when i give more than 10,it throws me an error while returning data in xml format.How can i get a looping products with 10 products one by one..


November 30th, 2014 at 6:24 am

ItemPage cannot be greater than 10. Each page returns 10 products for a total of 100 products. ItemPage can be only in the range 1-10.



November 30th, 2014 at 10:15 am

So if some catalogue has products in number of lakhs. Then is there any way to retrieve them sir?



November 30th, 2014 at 10:36 am

Thats fine.but how can we get rest of products if the list is quite big lets say we have lakhs of products for one can we access that then sir?


November 30th, 2014 at 8:18 pm

You will have to “drill down” using browse nodes to get other products. Any single category will not have lakhs of products, but will be further sub-categorised using browse nodes.



December 1st, 2014 at 6:37 am

Thanks man for helpful links.I have one small query lets say I searched for women in title in category apparel,so I got some results out of which only 10 products were displayed.

So we need to try using various words like shoes,men ,casual etc. like I used women in my search to search through apparel category!!.May be we will get same products for various searches then we can insert it by comparing with existing asin numbers.
Is my approach correct?
I am using search keywords at the place where you are using x-men-origins in your example.


December 1st, 2014 at 6:45 am

There is no right approach, but yours will work if you are using keyword for search. A better approach will be to use BrowseNodes to go to a subcategory. Also note that there is a limit to how much queries you can send to Amazon per hour. Please check the latest limit from their documentation.



December 1st, 2014 at 1:10 pm

K.thanks man for info



December 3rd, 2014 at 4:02 am

OMG..Just now i got access key and secret can i use these details to work with amazon api..i am completely new to this..Thanks in advance.



December 3rd, 2014 at 7:01 am

How to get item amazon price that is selling (from amazon)?

I was using this code below, but I see now it show “More Buying Choices”, not amazon price.


I tried to find it in php array but it doesn’t exist.
I guess I have to use new function instead of getItemByAsin.


Vinod Lalit

December 7th, 2014 at 5:22 am

Hi Sameer, Thank you for the well written code.

I am able to successfully run searchProducts() and getItemByKeyword() functions. But the other two functions (i.e. getItemByUpc() and getItemByAsin()) are returning invalid XML error message.

I have tried tweaking these two functions quite a bit in order to make them work. But to no avail. Both these functions are pretty simple, but still, I am missing something. Could you please confirm if they return good XML?

Thanks once again!


December 7th, 2014 at 7:05 am

Cannot really comment without knowing what the error message. In the ‘aws_signed_request.php’ file echo the $xml_response variable to see what error is returned.



December 7th, 2014 at 9:23 am

My comment is still “Your comment is awaiting moderation.”


December 7th, 2014 at 8:05 pm

homeland, will have to check, currently ‘m out on leave.


Amazon Search App that hides items | CL-UAT

December 28th, 2014 at 3:53 pm

[…] CodeDiesel Blog Article on it This is where the original scripts came from. […]


Getting the Top Seller items from Amazon using AWS

February 18th, 2015 at 12:40 pm

[…] a previous post we had seen on how to access the Amazon Product Advertising API. In this post we will see how to […]


Searching for a list of matching items in Amazons Product Advertising API - Technology

February 21st, 2015 at 12:12 am

[…] I am working with PHP and the Amazon Product Advertising API and I am trying to use ItemSearch to have a list of matching products. I am using the method found here […]



March 19th, 2015 at 11:29 pm

Hello Sameer,

Thank You! This article was a great help for me. All works fine!




April 10th, 2015 at 5:45 pm

Could not connect to Amazon. Public_key, private_key and Associate Tag are filled but still get this error. Any solution for this ?


anurag sharma

April 26th, 2015 at 3:27 am

we are using above code and getting an error “Invalid xml response”.
what i felt my URL is not right /onca/xml AWSAccessKeyId=XXXXXXXXXXXXXX&AssociateTag=XXXXXXXXXXX-XX&Operation=ItemSearch&ResponseGroup=Medium&SearchIndex=DVD&Service=AWSECommerceService&Timestamp=2015-04-25T21%3A43%3A30Z&Title=X-Men%20Origins&Version=2009-03-31
please help me


Pranoy Sinha

May 4th, 2015 at 8:26 pm

Great – It works for me. Thank you so much

Your thoughts