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.

<?php
 
    /* Example usage of the Amazon Product Advertising API */
    include("amazon_api_class.php");
 
    $obj = new AmazonProductAPI();
 
    try
    {
        /* Returns a SimpleXML object */
         $result = $obj->searchProducts("X-Men Origins",
                                       AmazonProductAPI::DVD,
                                       "TITLE");
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
 
    print_r($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.

<?php
 
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");
        }
        else
        {
            if (isset($response->Items->Item->ItemAttributes->Title))
            {
                return ($response);
            }
            else
            {
                throw new Exception("Invalid xml response.");
            }
        }
    }
 
    private function queryAmazon($parameters)
    {
        return aws_signed_request("com",
                                  $parameters,
                                  $this->public_key,
                                  $this->private_key,
                                  $this->associate_tag);
    }
 
    public function searchProducts($search,$category,$searchType="UPC")
    {
        $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD");
        $allowedCategories = array("Music", "DVD", "VideoGames");
 
        switch($searchType) 
        {
            case "UPC" :
                $parameters = array("Operation"     => "ItemLookup",
                                    "ItemId"        => $search,
                                    "SearchIndex"   => $category,
                                    "IdType"        => "UPC",
                                    "ResponseGroup" => "Medium");
                            break;
 
            case "TITLE" :
                $parameters = array("Operation"     => "ItemSearch",
                                    "Title"         => $search,
                                    "SearchIndex"   => $category,
                                    "ResponseGroup" => "Medium");
                            break;
 
        }
 
        $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.

<?php
 
function  aws_signed_request($region,
                             $params,
                             $public_key,
                             $private_key,
                             $associate_tag)
{
 
    $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.
    */
    ksort($params);
 
    $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".
                            $canonicalized_query;
 
    /* 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;
    }
    else
    {
        /* 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 : 10003 / 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]gmail.com for any new project requirements and price quotes.

91 Responses

1

Steven Klotz

August 22nd, 2009 at 3:59 pm

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

2

Sammie

August 28th, 2009 at 5:13 pm

Thanks for sharing your source. Very helpfull!

3

phplifestyle

September 4th, 2009 at 7:47 am

Thank for share. Great source.

4

Soediarto

September 20th, 2009 at 11:56 pm

Thanks for sharing..it helps me a lot..

5

Leo

September 21st, 2009 at 1:22 pm

Very helpful code! Thanks!

6

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.

sameer

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:

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/CHAP_ResponseGroupsList.html

8

cd smith

September 30th, 2009 at 9:58 pm

I tried that earlier unsuccessfully.

Here is what I did:

amazon_api_class.php

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

break;

Example.php

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.

sameer

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;

10

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;

sameer

October 1st, 2009 at 5:32 am

Just print the $result using

print_r($result)

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:

print_r($xml_response);
exit();

This will display the actual XML returned by Amazon.

12

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..

13

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 :)

14

Manuel88

October 12th, 2009 at 1:58 am

Finally a script that work!! Thnx man!!

15

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.

16

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?

17

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?

sameer

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.

19

Vishy

October 29th, 2009 at 12:29 pm

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

20

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”);

Thanks,
Anup

sameer

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:

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/USSearchIndexParamForItemsearch.html
#USSearchIndexParamForItemsearch_magazines

22

Rucha

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?

sameer

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");
.
.

to


.
.
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);

with


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:
http://www.browsenodes.com

24

Chandra Mouli

December 16th, 2009 at 8:51 pm

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

Regards
Chandra Mouli Tanikonda

25

Rucha

December 19th, 2009 at 3:39 am

Thanks a lot Sameer. Now it is working fine

26

XT@z

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 ?

27

Rucha

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?

Thanks…….

28

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?

sameer

March 2nd, 2010 at 9:56 pm

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

30

John

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.”
&Signature=”.$signature;

should be:

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

i.e no newlines in it!

Tookk me sometime to work out the problem :(

31

Sudeep

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.

Cheers,
Sudeep

sameer

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.

33

Sudeep

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.

Cheers,
Sudeep

34

Sudeep

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.

Cheers,
Sudeep

sameer

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.

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/CHAP_ResponseGroupsList.html

36

Sudeep

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.

Cheers,
Sudeep

37

freezeec

April 22nd, 2010 at 3:14 am

thanks so much !
The first php script which works !

38

CTRtard

April 24th, 2010 at 2:32 am

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

39

James

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

sameer

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’.

print_r($result);

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

$result->Items->Item->SalesRank;

Same with the other item properties.

41

James

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!

sameer

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:

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?CHAP_OperationListAlphabetical.html

43

James

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! ;)

sameer

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:

$result->Items->Item[8]->SalesRank;

(The index starts at ’0′)

To look at other item properties do a

print_r($result);

and then view the source of the page.

45

James

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 :(

46

Oli

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.

47

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 “”;
print_r($result);
echo “”;

Cheers
Amir

48

James

May 24th, 2010 at 1:21 am

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

49

hamza007.0fees

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

50

momkn

June 1st, 2010 at 4:26 pm

Thank you very much This is what I was looking

51

James

June 3rd, 2010 at 1:02 am

glad you all got it working :(

52

Chaitanya

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

Regards,
Chaitanya

sameer

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.

54

Chaitanya

June 13th, 2010 at 4:45 am

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

55

Ashfaq

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 ”;
$rowcount=0;
if ($bn != FIRST_TIME) {
foreach ($Result['MultiOperationResponse']['ItemSearchResponse']['Items'][0]['Item'] as $item) {
if (isset($item['SmallImage']['URL'])) {
$image=”;

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

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

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

}
}
else {
echo ‘Choose a category on the left’;
}

echo ”;

}

56

Sam

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

57

Irshad

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.

58

Brian

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 amazon.co.uk, 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!!!

59

simon

July 16th, 2010 at 11:25 pm

Sameer,

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?

60

Julio Montoya

August 3rd, 2010 at 1:20 pm

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

sameer

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.

62

john

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

63

john

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…….

64

Brian

August 16th, 2012 at 12:27 pm

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

65

Sham

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?

66

Shahzad

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.

sameer

September 9th, 2012 at 11:45 pm

Hi!

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;
exit;

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

68

Greg

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

69

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.
thanks

70

DHARMA

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
Dharma

71

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 Last.fm. Both have PHP code available showing you how to do basic and advanced [...]

72

Murali M

October 21st, 2012 at 6:52 pm

Samir

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

73

prasad

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

74

steve

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?

Thks

75

Muskie

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.

https://github.com/Muskie/MashupCode/tree/master/AmazonAPI

76

rey

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?

regards,
Rey

sameer

November 25th, 2012 at 6:41 am

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

78

jya

November 29th, 2012 at 10:02 am

THanks you so much sir!

you just saved a poor life.

79

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”);
break;

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: http://www.amazon.com/s/ref=sr_st?keywords=Anita+Baker&qid=1355907713&rh=n%3A5174%2Ck%3AAnita+Baker&sort=relevancerank

But I am getting different results as :
http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AWSAccessKeyId&AssociateTag=MYAssociateTag&Operation=ItemSearch&ResponseGroup=Medium&SearchIndex=Music&Service=AWSECommerceService&Sort=artistrank&Timestamp=2012-12-19T12%3A41%3A21Z&Title=anita-baker&Version=2009-03-31&Signature=MYSignature

Please tell me how can I get top 10 results as given url http://www.amazon.com/s/ref=sr_st?keywords=Anita+Baker&qid=1355907713&rh=n%3A5174%2Ck%3AAnita+Baker&sort=relevancerank

Thanks

80

Fabio

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
Fabio

81

Fabio

December 27th, 2012 at 7:41 am

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

Thank You again
Fabio

82

CD Collection Browser Mashup is basically done – Muskblog

January 20th, 2013 at 5:33 pm

[...] Amazon API by Sameer Borate [...]

83

Seto

February 6th, 2013 at 2:25 am

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

84

Iwan

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.. ^_^

85

Yovar

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.

http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=ACCESSKEY&AssociateTag=ASSOCIATE 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.

86

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 Last.fm API working. I’ve also discovered that making a lot of requests to these [...]

87

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 [...]

88

sanjiv

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

89

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 [...]

90

pankaj

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

Pankaj

91

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 http://www.codediesel.com/php/accessi…. i would like to get more than 10 product’s detail when i make a search query using amazon [...]

Your thoughts