Amazon API By Nabeel Shahzad (http://github.com/nshahzad) License: MIT -------- PHP 5.2+ API for interacting with Amazon's API. Very basic, and designed to work dynamically with Amazon's API, so any updates Amazon does should just work since the function is dynamically generated using PHP's __call() feature. The Amazon API list is here: http://docs.amazonwebservices.com/AWSECommerceService/2010-09-01/DG/CHAP_OperationListAlphabetical.html For instance, ItemSearch, so you call the function ItemSearch(), and pass any parameters to it in an array. Usage: -------- To use this class, include the file, and then initialize the class using your Amazon Key and Secret Key. They can both be obtained from Amazon at this page: http://aws.amazon.com/ Account -> Security Credentials include 'amazon.php'; $amz = new AmazonProductLookup('YOUR AWS KEY', 'YOUR SECRET KEY', 'LOCALE (default = US)'); There are three parameters: * Your AWS Key * Your AWS Secret ID * An optional locale, default is "US" That's all you need to do to initalize. Here's an example of an ItemSearch operation: http://docs.amazonwebservices.com/AWSEcommerceService/4-0/ApiReference/ItemSearchOperation.html $results = $amz->ItemSearch(array( 'SearchIndex'=>'Apparel', 'Keywords' => 'Shirt' ) ); $results is a SimpleXML object. An example of an ItemLookup: http://docs.amazonwebservices.com/AWSEcommerceService/4-0/ApiReference/ItemLookupOperation.html $results = $amz->ItemLookup(array( 'ItemId' => $isbn, 'ReponseGroup' => 'Small' ) ); Error Handling: ------- You can use exceptions to handle errors. When Exceptions are throw, the code is always -1. The error message is the short-hand code send by Amazon, and an additional function called getDetail() is available to show the detailed error message sent by Amazon: In this example, I removed the 'Keywords' Parameter: try { $results = $amz->ItemSearch(array('SearchIndex'=>'Apparel', /*'Keywords' => 'Shirt'*/)); } catch (AmazonError $e) { echo "Exception: ".$e->getMessage(); } The Exception thrown in: Exception: AWS.MinimumParameterRequirement And calling $e->getDetail() shows; Exception: Your request should have atleast 1 of the following parameters: 'Keywords','Title','Power','BrowseNode','Artist','Author','Actor','Director', 'AudienceRating','Manufacturer','MusicLabel','Composer','Publisher','Brand', 'Conductor','Orchestra','TextStream','Cuisine','City','Neighborhood'. If you disable exceptions, using $aws->throw_exceptions = false, the function will return false on an error, and you can use: $aws->getError(); $aws->getErrorDetail(); To return the last error codes