Thursday, December 27, 2007
Using Amazon Web Services with REST Part 1: Constructing The URL
Amazon's Web Services expose all their product information to developers using a couple of different methods: SOAP and REST. In this guide, I will look at how you can use REST, or XML over HTTP, to retrieve information. XML over HTTP is a URL-centric approach so the key to querying the Amazon data store is to construct a querying URL that has the right parameters to pull out the information you want. In this example, I am going to extract a list of bestselling Power Ranger toys from Amazon UK.
We start our URL with
http://
The first thing you need to do is then identify the right resource to connect to, which will depend on the regionality of the results you want. To extract information from Amazon UK web services, use:
xml-uk.amznxslt.com/onca/xml?Service=AWSECommerceService
The next step is to define the mode of operation. For instance, are you searching for a set of results or looking up a specific item. For this example, we are searching for a set of results, so add in:
&Operation=ItemSearch
It's at this point that I add in the developer's key which you get when you sign up to Amazon Web Services.
&AWSAccessKeyId=XXXXXXXXXXXXXXXXXXX (replace the Xs with your own)
You also need to add a parameter with the Amazon associate ID you want to use, so that the results have it embedded in them, creating the trackable deeplinks which will earn you money.
&AssociateTag=toysandvideogames-21
Next step is to define the "SearchIndex" in which you want to search. Examples include DVDs, VideoGames, Kitchen or Blended to search across indices. In this example, I will use toys:
&SearchIndex=Toys
The next important parameter is to define the search text which will bring back the appropriate results. The parameter is the "Title":
&Title=Power%20Rangers (notice that spaces are replaced with "%20" so the URL is not broken)
I'm next going to define the order of the results. Like when you are on the Amazon site itself, you can see the results in all manner of ways such as alphabetically sorted, in price order or see the bestselling first. I think being able to get the data in order of sales rank is such a useful thing compared to the functionality of static product feed files provided by most affiliate networks. Here's how you do that:
&Sort=salesrank
There's one more parameter we need to add in which defines the amount of information that Amazon sends back in response to your query. There's quite a few differing options, but for this example and for simplicity, I will just use this parameter, which asks for a "Large" response.
&ResponseGroup=Large
Ok, now if you concatenate all the bold snippets above into one long URL, you will have your completed querystring for pulling out information on the bestselling Power Rangers toys at Amazon, and it should look something like this:
http://xml-uk.amznxslt.com/onca/xml?Service=AWSECommerceService&
Operation=ItemSearch&AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXXX&
AssociateTag=toysandvideogames-21&SearchIndex=Toys&
Title=Power%20Rangers&Sort=salesrank&ResponseGroup=Large
The beauty of this is that you can test it instantly -just copy and paste what's above into the address bar of your internet browser and press enter and you will see XML data returned from Amazon with all the information on best selling Power Rangers toys (don't forget to watch out for line breaks when copying, and replacing the XXXs with your developer key from AWS).
Now that you have got the product data from Amazon in XML format, the next stage is to format it and display it on a web page so you can actually use it. There's a range ways to do that and I'll write about them in Part 2.
We start our URL with
http://
The first thing you need to do is then identify the right resource to connect to, which will depend on the regionality of the results you want. To extract information from Amazon UK web services, use:
xml-uk.amznxslt.com/onca/xml?Service=AWSECommerceService
The next step is to define the mode of operation. For instance, are you searching for a set of results or looking up a specific item. For this example, we are searching for a set of results, so add in:
&Operation=ItemSearch
It's at this point that I add in the developer's key which you get when you sign up to Amazon Web Services.
&AWSAccessKeyId=XXXXXXXXXXXXXXXXXXX (replace the Xs with your own)
You also need to add a parameter with the Amazon associate ID you want to use, so that the results have it embedded in them, creating the trackable deeplinks which will earn you money.
&AssociateTag=toysandvideogames-21
Next step is to define the "SearchIndex" in which you want to search. Examples include DVDs, VideoGames, Kitchen or Blended to search across indices. In this example, I will use toys:
&SearchIndex=Toys
The next important parameter is to define the search text which will bring back the appropriate results. The parameter is the "Title":
&Title=Power%20Rangers (notice that spaces are replaced with "%20" so the URL is not broken)
I'm next going to define the order of the results. Like when you are on the Amazon site itself, you can see the results in all manner of ways such as alphabetically sorted, in price order or see the bestselling first. I think being able to get the data in order of sales rank is such a useful thing compared to the functionality of static product feed files provided by most affiliate networks. Here's how you do that:
&Sort=salesrank
There's one more parameter we need to add in which defines the amount of information that Amazon sends back in response to your query. There's quite a few differing options, but for this example and for simplicity, I will just use this parameter, which asks for a "Large" response.
&ResponseGroup=Large
Ok, now if you concatenate all the bold snippets above into one long URL, you will have your completed querystring for pulling out information on the bestselling Power Rangers toys at Amazon, and it should look something like this:
http://xml-uk.amznxslt.com/onca/xml?Service=AWSECommerceService&
Operation=ItemSearch&AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXXX&
AssociateTag=toysandvideogames-21&SearchIndex=Toys&
Title=Power%20Rangers&Sort=salesrank&ResponseGroup=Large
The beauty of this is that you can test it instantly -just copy and paste what's above into the address bar of your internet browser and press enter and you will see XML data returned from Amazon with all the information on best selling Power Rangers toys (don't forget to watch out for line breaks when copying, and replacing the XXXs with your developer key from AWS).
Now that you have got the product data from Amazon in XML format, the next stage is to format it and display it on a web page so you can actually use it. There's a range ways to do that and I'll write about them in Part 2.
Labels: amazon, aws, REST, web services, xml
Comments:
<< Home
Very good information, IMHO this is going to be the standard for online marketing merchants have to open the API or give affiliates access to there stores info.
Waiting for the next part, which is the important part.
Waiting for the next part, which is the important part.
Thanks Vijay. Yep, I think any merchant who offers this has an edge over those that don't.
Come back soon for part 2...
Post a Comment
Come back soon for part 2...
<< Home
Subscribe to Posts [Atom]










