Accessing Amazon Product Advertising API


Posted in: libraries, php | Save to del.icio.us | 20 Aug 2009



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. 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";
 
    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);
    }
 
    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)
{
 
    $method = "GET";
    $host = "ecs.amazonaws.".$region;
    $uri = "/onca/xml";
 
 
    $params["Service"]          = "AWSECommerceService";
    $params["AWSAccessKeyId"]   = $public_key;
    $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 : 1567 / File size : 5.1 kB





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

Comments are disabled for this post, but if you have spotted an error, feel free to contact me.

Get latest updates by E-mail

About this blog

This site is a digital habitat of Sameer, a freelance web developer working from Pune.More

  • Users Online

    • 10 Users Online
    • 9 Guests, 1 Bot
  • RECENT COMMENTS

    ON TWITTER