Hi, every now and then people ask about how to access and use Amazon Associates Web Services, i.e. the Amazon API through which you can get XML data on the entire Amazon catalogue and build your own Amazon-powered store. I am no great expert, but I have been learning all this stuff recently so maybe it's just fresh in my mind! And rather than repeat everything I wrote to someone by PM recently, I will publish it here so others can make use of it. This is not meant to be some exhaustive guide, it's just supposed to get you thinking in the right direction. I COULD have put it in the XML forum, I suppose, but I think this is primarily of interest to Amazon associates. The only web dev language I have experience of is PHP (and not much at that!) and I am very happy with what I have managed to do with it (have a look at StoreMinator, an AWS-powered store - it mashes up other APIs too, like eBay and CJ), so I will tell you what I know about that! I can't say how this would be done with other languages, but it's all pretty simple stuff. Using SimpleXML PHP5 by default offers the SimpleXML extension/library, whatever you want to call it, which takes most of the legwork out of parsing XML. So you don't necessarily need a special library for AWS, like someone asked, though that would be handy! SimpleXML mostly does it for you. Accessing AWS So what you do is set up the API call string as described in AWS documentation, I think you can probably get that bit, but this is an example (though cheesily programmed, there is a PHP command for elegantly forming URLs, but for the life of me I can't remember it right now!): $APIcall = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&SearchIndex=PCHardware&AWSAccessKeyId=[YOUR]&Operation=ItemSearch&AssociateTag=[YOURAFFILIATEID]&ResponseGroup=Large&keywords=sausage"; $response = simplexml_load_file($APIcall); Code (markup): The ItemSearch call set up as "$APIcall" would look up items in the "PCHardware" SearchIndex specified using the keyword "sausage" (*shrug*), and would return a "Large" data set in response. To do that you use the simplexml_load_file function, with the $APIcall url as your parameter. Processing AWS results As a result of this code, the variable $response becomes a SimpleXML object, something like an array, containing field names and values - no regexp required! (though you may need to convert data to strings or integers to use properly). If you echo this (actually, print_r), you get LOADS of data, and you can see just how much potential there is in AWS. In particular you get image links and product links already loaded with your affiliate ID which you submitted when making the call. The data can be accessed like this in PHP, for example, you would cycle through each item as follows: foreach ($response->Items->Item as $item) { $Title [] = $item->ItemAttributes->Title; } Code (markup): The foreach loop is used to cycle through all elements of an array, and it works on "objects" too - this SimpleXML data is an "object", remember. The "->" is sort of like the "." in JavaScript or VBA, denoting the hierarchy in the object. So you are setting up "Item" as your point of recursion. If you look at the XML, each Item has an ItemAttributes subset, and Title is a subordinate value to that. So this will build an array called $Title with all the titles in it! This is quite simple, but you can see how by adding further loops (e.g. for each Item also recursing through the list of Reviews, say), you could build up a set of variables/arrays, with your relevant data. Now don't ask me how to parse the ChildNodes (as someone did), I haven't quite got my head round that because there is loads of deep recursion going on there, not sure how you handle that! Displaying AWS data Now, to display this basic data as HTML it's as simple as saying, e.g.: foreach($Title as $CurrentTitle) { echo "<h2>".$CurrentTitle."</h2>"; } Code (markup): Actually, you would write some sort of templating system where you would make a little HTML file containing tags like, say <h2>${Title}</h2>, which you would then search/replace with the relevant data, much neater than echoing like this. What are you waiting for? Now, there might be a simpler way of doing this, or one that's more in line with good coding practice, but I hope that helps get you started. It's actually very simple, but very powerful, and this should help you get your head round the idea. You do need SOME coding knowledge, though not much (if I did it...) and you can do wonders with AWS! Then you can stop building those *&^*& aStores too! Or indeed any other off-the-shelf package which makes your stores look the same as everyone else's and thus get ignored by Google. Viva web services!
Great tutorial mate! I have been trying out your code, it works well, the only problem I encountered was the "keywords" in the APICall, at the end its supposed to be "Keywords" with a capital "K" I have a question though, if I am to start affiliating for Amazon and I want to provide the items on my website i.e. add them to a shopping card etc on my website. Will I need to create a page for each product manually? Is their a way to apply a template to create a new product page automatically when it is added to Amazon? Also, will I need a new webpage for each search result if I am to have search bar function? Cheers
Oops! You're right - dunno how that got through. Unfortunately I can't change my original post now, but hope people will figure it out. All this stuff IS case-sensitive (you wouldn't believe how many times I have started at the word "Searchindex" asking myself, why won't it work..!?) I am not entirely sure I follow what you want to do - are you planning to create individual products pages manually? What most people are doing are using this data to entirely dynamically generate pages (though some are using a database to store/cache the data, but still, it's not created manually). So you write a script which will create, say, hundreds of pages featuring products from Home and Garden, purely by letting the API serve up all the bestsellers from that category. So when your site has a page: yourdomain.com/browseshop.php?SearchIndex=HomeandGarden&page=1 you will have a script on that page which downloads the bestselling products from the SearchIndex specified and from the page specified. Then, say, you have a page browser which allows the user to cycle through page=2, page=3 etc. (the API paginates results, usually in groups of 10, in case you didn't know). By the way, I don't advise just flooding your site with product pages from a particular SearchIndex - this will just create duplicate content problems. It's just an example, you want to be a bit more imaginative than that. As for searching, well, you will probably have a page called search.php which will pass the users search keyword to the API string in the form Keyword=$userkeywords and return a page, or multiple pages of results. Any product can be passed to the Amazon cart which is hosted by Amazon through the API, and you can have the customer buy everything through Amazon once they have stocked up their cart. You could do this with static pages too I suppose. By the way, I have never set up an Amazon cart myself, but I gather it's pretty simple. Hope I answered some questions, if I understood them right.
Could you elaborate on this a little , what kind of a script would this be? Initially I was planning on calling the API to return the results and then pass in variables retreived from the XML into the html and stylish it with CSS, im guessing this is a bad way of approaching it as I thought 'How do I pass variables into a html file that doesn't exist for that product'. Could you provide a simple example of what you are explaining ? I know about the whole duplicate content thing, im basically looking to pull information such as title, price etc, i plan on writing descriptions, review etc myself. Maybe a small example of this too . Would really appreciate it.
I have horrible amounts of work on, and I have a feeling this would take a full-on PHP tutorial, so here is just something to keep you going - will try and add to this if I have time (one day, in this life). You want to search Amazon products. So you make a php page called search.php as follows: <?php // NOTE: code not tested! It should work, but missing semicolons and the like are always a possibility! // Hard-coded variables $MyDeveloperID = "iugghKLHJGKLJHJKH"; // whatever ID you got from Amazon $MyAffID = "sexy-fish-20"; // your Associates ID // Variables to be got via GET $SearchIndex = $_GET['SearchIndex']; $Keywords = $_GET['Keywords']; // Get the parameters passed to the php file $APIcall = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&SearchIndex=".$SearchIndex."&AWSAccessKeyId=".$MyDeveloperID."&Operation=ItemSearch&AssociateTag=".$MyAffID."&ResponseGroup=Large&keywords=".$Keywords; // Make sense? You are plugging in the data you have either hard-coded (like your Dev and Aff IDs) or you have got from the user submission via GET $response = simplexml_load_file($APIcall); // get the XML data if ($response) // Check there WAS a response! { print_r($response); // this will just list the XML object in a user-readable form. You will want to parse this as described in an earlier post, by recursing through, saving the data in arrays etc. That's for another guide! } else { echo "Something went wrong - boo-hoo!"; // if there wasn't any result for some reason } ?> Code (markup): Then you can test this by typing mydomain.com/search.php?SearchIndex=PCHardware&Keywords=aquarium ...and hey presto! Of course, your user isn't going to type that stuff manually, you are going to make them a nice HTML search form where the SearchIndex is chosen from a drop-down list and the keyword is typed into another field (just look at Amazon, or my site, the usual thing) and this data is submitted via GET to the page we just made. Hope that's SOME help - I am not sure how much you need with PHP etc. I am NO PHP expert, believe me, you don't want to learn good coding practice from me! And I certainly can't write a tutorial for that, this was just a little nudge in the right direction and some programming knowledge IS needed to get anywhere with this. But that is essentially a way to make a search page and access AWS. It's really what you do with all that lovely data you get back in $response that will decide whether you succeed in creating that killer Amazon app!
Thanks for this mate, but i think i may have asked the question wrongly lol, but this is still great tips for the search function, the thing I was looking to know was this: When the user uses the search function on my website and I use the API to gather the products and sort them etc, then when the user clicks on one of these results I want the product to to load in a page of its own with a full description, reviews etc of the product <- this is my problem. Am I required to create a webpage for each product I want to have on the website? Also, how would I know what the link to the correct product page will be when I pull the results from Amazon? Do you have any idea of how this can be achieved? Sorry for all of these questions, I greatly appreciate you taking the time with them, but if you know any resources that have these answers then please do provide the links as ill appreciate these just as much. I have a strong programming background, its just the logic of how these things can be achieved is what im struggling with
I'm sure it will be useful for someone anyway! I can't remember finding any resources that explain this really simply, so I had to figure out a lot by myself, so I will try to pass on what I can. The way to implement what you are saying above is probably going to be by having two PHP pages. One is, say, browse.php, where you pull ten results at a time and display the basic product information. This would be done with the ItemSearch call. However, with each result, instead of displaying the direct link to Amazon which you get, among other things, through the API, you would use a unique identifying feature of the product to link to another page on YOUR site. This one could be called product.php and you would link to it probably with the ASIN, as every Amazon product has one of these. So you get the ASIN for each "browsed" product and link to product.php something like this: product.php?ASIN=$ASIN. Now your product.php GETs the $ASIN and uses a NEW lookup to the Amazon API, but using the ItemLookup method. This is a typical ItemLookup call: http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[accesskey]&Operation=ItemLookup&AssociateTag=rubber-george-bush-20&ResponseGroup=Large&IdType=ASIN&ItemId=B000OH26OM Code (markup): This one gives you much more detailed info, but only about one item, based on its unique code - ASIN, ISBN, UPC, whatever you specified (you also choose the type of code in the call, using IdType). Here you get just about every conceivable bit of info about the product, including of course another direct link to Amazon, but again, you could implement a cart on your site using the APIs built-in facility. Of course, all this would be a bit different if you were using a database and somehow storing all the product data - it would reduce the number of API calls (you are limited to 1 per second, supposedly), but then there are all sorts of other problems relating to maximum allowable caching time (Amazon TOS) and to how you are going to "spider" all those products. Hope this helps. You DO have complete Amazon documentation here http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=19 (choose the latest version of the Web Services docs and note that there are basic, get-you-going docs and full technical docs so you will want to start consulting the latter fairly quickly). These should be at least a little bit clearer (I hope!) after my explanation!
Great post I was lazy enough to get going but your thread reminded me about my amazon store and I have now finally put it together. Thanks.
I just set up one of their "Astores" for free. I am trying to drive traffic to it and will post here if i see it working or not.
Cool, but PLEASE don't post it in this thread!! This thread is about anything but aStores and to be honest I am sick of hearing about them. Good luck with it, but don't expect miracles - at some point you will probably start wanting a custom solution like we are talking about here.
Not spamming my link. But Just thought people would like to see this thing in action. Here I have implemented it http://www.lawrencia.com I added some more features like cache and all. Markowe thanks for nice and simple explanation on it. Thanks.
Great start, but I am wondering why you go right to amazon when you click buy. They have a way to actually shopping cart it on your site and then only go there for checkout. One thing I have discovered is that if you can get a few items in the cart they are less likely to bail when you take them to another site to checkout. The php sample on amazons developer page does have tons of code issues but I managed to doctor it up, but only for my specific niche. I was planning on going further with it (full solution with all catagories etc) but didnt know if a solution existed (I assume commercial and costly) or if there would be a market for it (at a lower cost to cover coding time etc) This is what I have started with which i think builds a little on what you have as far as functionailty but maybe not as pretty and shopping cart styled as you have. Good work though..and great thread. My site demo is the Wii site in my sig.
Sure, I am aware of the cart aspect of the API. I am still in two minds about it - I think you have to build a lot of trust with your site in order for people to actually consider buying from "you". I certainly don't start loading up my online cart on any old site I come across. When you send them straight to Amazon, or wherever, at least you are getting the cookie in there, as it were, and you hope Amazon will do the rest. Also, what to do if you have multiple retailers on your site? You could make a sort of unified cart but obviously checkout couldn't be done for all of them simultaneously, and I presume the eBay and CJ API don't even have a cart function. So I AM thinking about it, but I guess just building up the SE presence at the moment and relying on organic traffic rather than return, loyal customers. Like the Wii site anyway - I think wonder can be done with a niche Amazon site if you are prepared to invest time and effort.