Resources



Sample Code and Libraries

Amazon Associates Web Service Simple Store in PHP

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

This is a simple PHP 5 application demonstrating the basics of how to interact with Amazon Associates Web Service.

Submitted By: Philip@AWS  
AWS Products Used: Amazon Associates Web Service
Language(s): PHP
License: Apache License 2.0

About This Sample

  • Based on the 2006-09-11 API version.
  • This application is meant to demonstrate the ItemSearch, ItemLookup, CartCreate, CartAdd, and CartModify operations. It is not intended to be be comprehensive example of how to build an e-commerce store. For example, on an ItemSearch by Keywords, this sample only returns items that are for sale by Amazon (as opposed to other Merchants).
  • This sample was tested on PHP 5.1.4.

What's New

  • 2007-04-06: This sample now presents a "See Cart Contents" link when items are in the shopper's cart. Previously, a shopper could only see cart contents upon adding an item to the cart.

Prerequisites

  • You must have a valid Amazon Web Services developer account. (You can create one here: http://aws.amazon.com)

Running the Sample

  1. Replace YourAccessKeyIdHere wih your AWS Access Key Id near the top of the simplestore.php file.
  2. [Optional] Replace YourAssociateTagHere with your Associate Tag near the top of the simplestore.php file. This needs to be done if you want to earn referral fees for sales you generate. You can learn more about our associates program here.
  3. To run the sample, put SimpleStore.php in your root directrory and load SimpleStore.php?Action=Search in your browser.


Related Documents
Type: Articles & Tutorials Making Money with the Associates Program, and PHP

Discussion

The 5 most recent discussion messages. View full discussion.

"ganswijk"
Posts: 757
Registered: 2/8/06
Re: Amazon Associates Web Service Simple Store in PHP
Posted: Jul 18, 2009 8:07 PM PDT   in response to: Aaron
 
  Click to reply to this thread Reply

I have recently upgraded my PHP script on:
http://www.chipdir.nl/amazon/
so it will keep working after august 15.

The script still isn't perfect yet, but it works and has a lot
of useful comments in the source code (as someone
remarked via email). It has a flag with which you can
enable or disable the new mechanism which isn't very
useful after august the 15'th of course and I will remove
the old code parts later. Until that date you can still
test both variations of the script which might help
debug your situation.

Feel free to email me with questions or suggestions
or whatever to encourage me to spend more time on
the script. ;-)

I can understand that my old friend Mr. Rat has stopped
developing his script because Amazon keeps changing
the rules of the game.

Anyway, my script works as it is, except that you have to
include your own two Amazon keys from august 15'th
onwards.

Someone noted that my script works perfectly under Linux etc.
but provokes a lot of 'notices' under Windows, but my scripts are usually
very solid so just disable these warnings by using the error_reporting function:

error_reporting(error_reporting()&~E_NOTICE);

I'll add this to the script the next time I'll edit it.

To Amazon: I think that you should refer to my script and refer to it as seemingly the leading (because only) independent PHP script that has survived all of Amazon's noncompatible programming interface changes.

Most other scriptwriters have given up by now...


M. Buth
RealName(TM)
Posts: 14
Registered: 7/31/09
Other Countries / Download Button
Posted: Jul 31, 2009 4:33 AM PDT   in response to: Rommel C. Santor
 
  Click to reply to this thread Reply

Where can I obtain the URL for other Amazon sites such as Amazon.de ?
Regarding the Button: Have you tried various browsers ? I use firefox and the button is visible.



adamcox9
Posts: 6
Registered: 9/30/08
Re: Amazon Associates Web Service Simple Store in PHP
Posted: Aug 1, 2009 3:25 PM PDT   in response to: trantrung
 
  Click to reply to this thread Reply

I believe this does the trick:

...

$timeStamp = gmdate("Y-m-d\TH:i:s\Z");

//service is always the same, $function is operation
$string = 'AWSECommerceService'.$function.$timeStamp;

$signature = base64_encode(hash_hmac("sha256", $string, SECRETKEY, True));

$params = array('Service' => 'AWSECommerceService', 'AssociateTag' => ASSOCID, 'AWSAccessKeyId' => TOKEN, 'Signature' => $signature, 'Request' => array($array));

$client = new SoapClient("http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl", array('exceptions' => 0));

return $client->__soapCall($function, array($params));

...

It still works if I put anything in as the signature, so I'm not sure. I might have to wait until August 15th to see if it is correct.

Learn more at AWS Signed Requests with PHP and Soap

Message was edited by: adamcox9

Glenys Davey
Posts: 1
Registered: 6/23/09
Re: Amazon Associates Web Service Simple Store in PHP
Posted: Nov 5, 2009 1:41 AM PST   in response to: Aaron
 
  Click to reply to this thread Reply

hi i own quite a few affiliatte [associatte]sites and i have been with amazon.com over 1.or2 now;please tell me how the sales have been doing.how do i get paid;husky121 dvd_buster@ymail.com

Cindy@AWS
Posts: 242
Registered: 1/28/09
Re: Amazon Associates Web Service Simple Store in PHP
Posted: Nov 6, 2009 3:15 AM PST   in response to: Glenys Davey
 
  Click to reply to this thread Reply

Hi Glenys,

If you are an Amazon Associate with a question regarding getting paid, please use the Amazon Associates contact form:

https://affiliate-program.amazon.com/gp/associates/contact

If you have a technical question about the Amazon Product Advertising API, then please post in their developer forum located here:

http://developer.amazonwebservices.com/connect/forum.jspa?forumID=9&start=0

If you are not using the Amazon Product Advertising API, but would like to discuss the Amazon Associates program with other associates, then please post to the Amazon Associates discussion boards, which are found here:

https://affiliate-program.amazon.com/gp/associates/login/login.html

Best Regards,
-Cindy



Reviews
Create Review Write a Review

function simplexml_load_string, Feb 8, 2007 10:01 AM
Reviewer: Ken Torimaru
The function simplexml_load_string appears to be missing.

PHP5 Solution, Feb 10, 2007 5:48 AM
Reviewer: innindia
This solution is meant for PHP5 & higher. If you are running it on lower versions of PHP, "simplexml_load_string" function would not work...as it is not available in versions lower to PHP5. Regards Arijit www.innindia.com

Just what I needed, Feb 14, 2007 9:25 AM
Reviewer: defrex
A good quick script to get in idea of how to use the api.

Humm, no more informations ?, Feb 16, 2007 12:11 PM
Reviewer: aliasjokester
I wanted to use the search mode, but it isn't as well as i expected : can we have any more informations about products ? Year of publication, editor etc... are usefull. Jk.

Error Message, Mar 9, 2007 8:48 AM
Reviewer: Johannes P. Wilbrand
... for your information ... putting something into the shopping cart and trying to remove it again gives you a nice error message: Invalid argument supplied for foreach() on line 218

Ive got PHP5 but why do I get errors?, Apr 26, 2007 4:00 AM
Reviewer: toxitalk
I get a number of errors to do with uninitialised variables and undefined index's (CartId and HMAC) Help.

Excellent!, May 2, 2007 6:22 PM
Reviewer: centerax
WOW, this worked great on me. Thanks, it is very simple but very powerfull. I'm surprised. :D

NICE!, Jun 7, 2007 9:33 PM
Reviewer: kevchuey
Phenomenal. Works like a charm, and like some of the other comments: simple, yet very powerful.

nice base, Jul 14, 2007 9:11 PM
Reviewer: crudpuppy
Had some issues with some of the stuff bombing(due to things like type casting needed) but its still VERY slow to run...is this just expected from amazon's api or is it the fundamentals of the script and the way it works?

Great start, Jul 16, 2007 12:06 PM
Reviewer: davidstone78
It really is a great base to work from. I wonder if anyone else has encountered the slightly confusing issue of what happens when you add a second item to the shopping cart? I.e. both disappear!

Amazon ECS Simple Store in PHP, Aug 7, 2007 10:17 AM
Reviewer: rocasespino
I have the same error than Toxitalk. What can we do? Thnks

Awesome, Aug 19, 2007 10:01 AM
Reviewer: vernonmorris
This is great! Works perfectly with php 5! Thanks so much!

Doesn't work for me, Sep 5, 2007 9:43 AM
Reviewer: Doctor 3D
I don't see how this script can work properly. $CartID and $HMAC are not getting passed around correctly. For example, right at the top it prints the FORM containing hidden INPUT fields with VALUEs set from variables $CartId and $HMAC. Problem is - those 2 variables are not retrieved until code that comes *after* the print() call.

PHP Code, Sep 7, 2007 3:13 AM
Reviewer: prince1980
there is no suficient documentation for implementing it.

work perfectly on php5, Sep 15, 2007 10:54 AM
Reviewer: me@bowu.org
very good example for understanding the php api.

Worked Fine but..., Sep 22, 2007 4:24 AM
Reviewer: Christopher Dixon
Not what I expected. Why would I only want to see the high price? I want the low price too. Chris

Thanks for this script, Oct 6, 2007 12:39 PM
Reviewer: hidetaka2
I tried to implement my own script at the beginning but could not obtain something good as I would have expected. I then decided to try this SimpleStore.php script. I was very someone added this. Nevertheless I firstly add this problem: The CurlInt() php function was said to be unavailable -> had to have Apache load the module (php.ini) on the server. This solved one of the problem. Then I tried the SimpleStore.php again and it show me those errors: Notice: Undefined variable: CartId in ...\SimpleStore.php on line 30 Notice: Undefined variable: HMAC in ...\SimpleStore.php on line 32 What should I do for those variables? Finally, I dont know if thi is related with the undefined variable problem, but whatever the keywords or the category I choose, the result will always be "No match Found". May someone help me please? Hidetaka

Very Impressed, Oct 8, 2007 5:29 AM
Reviewer: conrad10781
As with most pieces of code that try and help you explain things, this does a great job, I don't think by any means was this package meant to be dropped to start everyone with a very involved system, which is exactly why its a 'simple store' and has little to no graphics. The lesson is to see how to interact with the Amazon API, and it does a great job. I saw a review that said 'Why would I only want to see the high price?' You could explore more with the API and do whatever you want. There is a lot this didn't go into, but again that is why it was labeled 'simple'. Great job!!

Error suppression, Oct 12, 2007 10:08 PM
Reviewer: AdBabel
For people who are worried about the error message on running this script simply add error_reporting(0); enclosed in PHP start/end tags at the top of the script. The error messages are warnings because the variables are not populated until the first search is executed. In any case, remember that this is a basically a demo script to show how ECS can be accessed using PHP. If error messages frighten you it's probably better to learn a bit more PHP :) (4 stars because of the lack of documentation/guidance for PHP neophytes.)

PHP5 or above ONLY, Apr 10, 2008 1:25 PM
Reviewer: Russ
Ken Torimaru, you're not using PHP5, see comments below + requirements

worked awesome., Jul 13, 2008 8:40 AM
Reviewer: matkahtml
The only thing i had to do was enable "php_curl" library in wamp and restart all the services.

Issue with Operation, Dec 18, 2008 1:47 PM
Reviewer: jon027
Loaded the php file on a webserver and it displays without issue but any search never returns any results. I entered my Access Key ID where needed and activated it from the Amazon email. No errors at any point just no results from the search. Thanks

works right out of the box, Jan 28, 2009 8:49 PM
Reviewer: madplay
Awesome!

Works perfectly, Apr 9, 2009 10:54 PM
Reviewer: B. Truong
Works perfectly, without a trouble. Easy to setup. Just add your associates id and upload, just like that.

Thanks for sharing, May 12, 2009 9:29 PM
Reviewer: cschuermyer
Works great. Just needed to change a couple of things that are already covered in the thread. Thanks!

error message, May 20, 2009 9:12 AM
Reviewer: jester joker
I get a, No matches found error message no matter what I search for?

Can't Get It To Work, Jan 30, 2010 11:25 AM
Reviewer: vgtradez
Tried everything but can't get it to return results. No matter what you search results it just returns no matches found.

Problems running example, Feb 9, 2010 7:11 AM
Reviewer: cis123
It seems to load fine for me but anytime I search for anything I don't get any results back. I'm not sure why this is. Could it have anything to do with the proxy settings? If so, how would you go about setting the proxy in this example?
Welcome, Guest Help
Login Login