Friday, December 28, 2007
Using Amazon Web Services with REST Part 2: Binding Data To A Web Page With ASP.net
In Part 1, I showed how to construct a URL which would pull out data from Amazon's web services on the best selling Power Ranger toys. With that part done, it's now time to think about how we make use of that data by using it in a web page.
For this example, I am going to show you how I do this using VB in ASP.net. I realise that ASP.net is a bit of a minority interest and it seems like most people out there are using PHP. I will add tutorials for other options later on, but today I will just do ASP.net and for that you will need web hosting space which supports the .net framework.
Overview
ASP.net comes with some nice controls which you can easily bind to an XML data source. The only challenge here is that to use them in their simplest form, they like the XML source to be rather flat in structure. Unfortunately the XML from Amazon is quite complex and has many layers to it which makes it trickier than I like to bind to a data control. So the way I do it is in two steps:
1) Apply an XSLT transformation to the XML source to "flatten it" and just give me the data I want.
2) Bind the transformed XML to my data control.
There will surely be other ways to achieve the same goal, but this is the way I to do it to achieve the result I want with the skillset I have.
Use XSLT to Transform and Flatten the XML from Amazon
Amazon's Web Services have an XSLT processor which means you are able to apply an set of XSL rules to the XML it generates. I have written the following XSL tranformation which extracts key information from the AWS Large Response I mentioned in the previous post and outputs it as more simplified, flatter XML.
See XSL Transformation file (save with .xslt extension to use)
If you want to try following this example, you can save that text file as something like transform.xslt and upload it to your own webspace. I will also zip it up with and make it available for download with the web page source code which I will come to shortly.
Once it has been uploaded to some webspace that you have accessible to you, you then add a Style parameter to the querystring that we built in Part 1.
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&Style=http://mydomainname/transform.xslt
Bind the Data to a Web Page Control
Now that the source XML is a simplified form, it's very easy to bind to a data control in a webpage in asp.net. I won't explain too much but just give you the source code. It's really hard to paste code into Blogger without it kicking up a fuss so here's a link to the source code in a text file.
ASP.net Example Source Code
Replace the XXXXX in the code with the URL from Part 1 and then save that with a .aspx extension, upload it and then access it in the browser and it should look something like this.

There we have it - live product information from Amazon with the best selling Power Rangers toys. That's one way you can do it in asp.net using VB - I'm sure there are even better ways. I'll soon post up instruction on achieving the same using different development environments.
Use at your own risk - remember your web server needs to support asp.net
Any questions?
For this example, I am going to show you how I do this using VB in ASP.net. I realise that ASP.net is a bit of a minority interest and it seems like most people out there are using PHP. I will add tutorials for other options later on, but today I will just do ASP.net and for that you will need web hosting space which supports the .net framework.
Overview
ASP.net comes with some nice controls which you can easily bind to an XML data source. The only challenge here is that to use them in their simplest form, they like the XML source to be rather flat in structure. Unfortunately the XML from Amazon is quite complex and has many layers to it which makes it trickier than I like to bind to a data control. So the way I do it is in two steps:
1) Apply an XSLT transformation to the XML source to "flatten it" and just give me the data I want.
2) Bind the transformed XML to my data control.
There will surely be other ways to achieve the same goal, but this is the way I to do it to achieve the result I want with the skillset I have.
Use XSLT to Transform and Flatten the XML from Amazon
Amazon's Web Services have an XSLT processor which means you are able to apply an set of XSL rules to the XML it generates. I have written the following XSL tranformation which extracts key information from the AWS Large Response I mentioned in the previous post and outputs it as more simplified, flatter XML.
See XSL Transformation file (save with .xslt extension to use)
If you want to try following this example, you can save that text file as something like transform.xslt and upload it to your own webspace. I will also zip it up with and make it available for download with the web page source code which I will come to shortly.
Once it has been uploaded to some webspace that you have accessible to you, you then add a Style parameter to the querystring that we built in Part 1.
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&Style=http://mydomainname/transform.xslt
Bind the Data to a Web Page Control
Now that the source XML is a simplified form, it's very easy to bind to a data control in a webpage in asp.net. I won't explain too much but just give you the source code. It's really hard to paste code into Blogger without it kicking up a fuss so here's a link to the source code in a text file.
ASP.net Example Source Code
Replace the XXXXX in the code with the URL from Part 1 and then save that with a .aspx extension, upload it and then access it in the browser and it should look something like this.

There we have it - live product information from Amazon with the best selling Power Rangers toys. That's one way you can do it in asp.net using VB - I'm sure there are even better ways. I'll soon post up instruction on achieving the same using different development environments.
Use at your own risk - remember your web server needs to support asp.net
Any questions?
Labels: amazon, asp.net, aws, REST, web services, xml
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
Tuesday, October 09, 2007
Cool side effect of using Amazon API
Something that I have noticed since using Amazon's Web Services is that quite often Google will index Amazon links with my associate ID in them, and rank them highly. It seems that when Google's crawling my site, somehow it takes one or two affiliate URLs and places them in the SERPs, usually as the top result, because they are actually pages on the Amazon domain, which obviously is a big authority domain.
Although Google crawls my site which has hundreds, or even thousands of AWS-generated links, only one or two will show up at any one time in the SERPs. I'm not entirely sure why it's happening, but it seems to last a day or two before disappearing, and then another one will spring up in its place. It's almost as if Google adds it to the SERPs, takes a day or two to realise it made a mistake and replace it with the plain Amazon link, but then makes the same mistake again and adds a new one to the SERPs.
I've never seen this happen with any of my plain text Associate links that I've created in the Associate control panel, only with links generated from the Web Services API. If you use the API and want to see if any of your links have been indexed and ranked (though a spike in sales for a specific product is usually a giveaway), you can use the allinurl operator on Google.
e.g. search for allinurl:associateid-20
(replace associateid and 20 with the right values for you!)
Put that down as another great reason to use Amazon's Web Services.
Although Google crawls my site which has hundreds, or even thousands of AWS-generated links, only one or two will show up at any one time in the SERPs. I'm not entirely sure why it's happening, but it seems to last a day or two before disappearing, and then another one will spring up in its place. It's almost as if Google adds it to the SERPs, takes a day or two to realise it made a mistake and replace it with the plain Amazon link, but then makes the same mistake again and adds a new one to the SERPs.
I've never seen this happen with any of my plain text Associate links that I've created in the Associate control panel, only with links generated from the Web Services API. If you use the API and want to see if any of your links have been indexed and ranked (though a spike in sales for a specific product is usually a giveaway), you can use the allinurl operator on Google.
e.g. search for allinurl:associateid-20
(replace associateid and 20 with the right values for you!)
Put that down as another great reason to use Amazon's Web Services.
Labels: amazon, aws, web services
Subscribe to Posts [Atom]












