Amazon Web Services using NuSOAP

Here’s a little article about connecting to amazon web services in PHP using NuSOAP.

Getting started

Firstly, get yourself over to NuSOAP and download a copy of NuSOAP. Scott Nichol is now the one who does most of the coding on this project appearance and he has a number of tutorials.

Then of course you’ll need to get hold of the amazon web service SDK and get a developer token. Its all free so no worries there.

Unpack NuSOAP to a directory, and create a new file called amazon.php. This file will be where we place our lovely code to get the details from amazon.

The Code – Keyword search

First we need to include the NuSOAP files:

Next we need to create out soap client and set some basic variables up:

The namespace and action are the same in the case of amazon, but often they might be different.

There are two main types of searches I do, one is the keyword search, and the other is the browse node search. I’ll cover the keyword search first and then highlight the differences between the two.

For a keyword search we need to pass in an array of parameters, detailing what we want to search for, where, and what we want returned. Here is an example:

keyword: The keyword value should be what you want to search for (e.g. ‘walks, lake district’ or ‘programming, .net’)
mode: This is where you should search in the amazon database, and example values are ‘books’, ‘dvds’, ‘music’. Regional variations exist for some modes, e.g. ‘books-uk’.
devtag: This is your developer tag
locale: Here I’m using the ‘uk’ locale, so prices etc. are returned in £ from the UK database. The default is ‘us’.
type: This is the xml-schema used to return the details. In most cases the ‘lite’ one will be enough, unless you also want reviews, comments and used item sale details as well.

Then we actually do the search:

The result is an array with many properties, but the one we are most interested in is the Details value, which itself is an array of the items returned.

As you can see here I’m not doing anything with these values, but you can then output them, stored them in a database or whatever.

The Code – Browsing a Node

For browsing, the only difference is the method and the params array:

Here browse_node will be the node number, taken from an amazon URL (look for “../browse/-/123456/..” in the URL, where 123456 is the node number.)


Well I hope that was easy enough. Of course there are a lot more details returned in the resulting array, especially if you choose ‘heavy’ as the type. Also, there are a number of other optional parameters you can pass in, such as sort order you want the results returned in. There are also other types of searches, such as artist, author, list mania or ever wishlist searches.

And finally, the new version of PHP, version 5, which has just been released has new built in support for SOAP, so eventually the NuSOAP package will become defunct to some extent.

Look out for a forthcoming article about how to create server site SOAP web services, including WSDL generation using NuSOAP.

[Listening to: The Chokin’ Kind – Joss Stone – The Soul Sessions (03:37)]

Changes to the website…

You might have noticed that the site has had a bit of a facelife. For a while now I’ve been meaning to give it an overhaul, and make it easier to update.

Things I’ve done:

  • Made templates wider.
  • Used amazon web services to get keywork and browse based item links
  • Added google ads at the bottom of the page
  • Created my own PHP base web service (using NuSOAP) to allow me to write a .Net application to manage my walks and blog posts (Moveable Type API) (this is partially completed – walks are done – blogs aren’t).
  • Created above noted app for managing walks database, written in .Net with some nice looking custom controls.

Things still need to be done:

  • I’d love to make the whole site run off one template – at the moment its 4, 1 in Dreamweaver for the walks, 1 for the index page and 1 each for the category and article pages.
  • Complete the above .Net application to cover blog editing
  • Add some caching to the above app, as at the moment it pulls a big list from the web each time it starts and slows everything down, probably churning my bandwidth as well)
  • Maybe improve the amazon keyword searches based on some info from each post – might be interesting :D

I think I’ll share some of the stuff I’m doing above later, specifically the .Net MoveableType class library and the amazon php soap client code, but both need a bit of tidying up first (especially the MoveableType bit).

MSDN in Firefox fecked!

Scott on Writing

At last an answer the problem I have been having with MSDN recently inside Mozilla Firefox 0.8 – and hopefully the guy’s issue will be raised to the right people and it will be fixed.

At least its not just me!

New version of FxCop

There’s a new version of FxCop been released – v1.30. Looks very nice, although there is some debate ongoing about some of its new performance rules.

Also it now nolonger locks the assemblies its analysed – a feature long in the waiting for!

On the other hand there is a small bug where you can no longer click on the code link to go straight to the code if there is a space in your pathname – very annoying and a fix is due to be released (soon I hope).

FxCop Team Page

Microsoft releases open source product

Is this a first? Microsoft have released one of their internal development tools as an open source product, on SourceForge no less.

The tool is an XML based Windows Installer (MSI) creation tool, used internally within Microsoft by a hell of a lot of people, and it has now been released into the wild.

I look forward to trying out this product and seeing what it can do for me, should be interesting.
Continue reading “Microsoft releases open source product”

Whidbey Community Technology Preview – Part I

Finally got it installed, so am going to go over some things I notice and like/dislike.

Firstly, I didn’t get to have a look at the PDC version of Whidbey, so I don’t know what differences there will be between that and this.

Secondly – its a pre-beta version, or alpha, so I don’t expect everything to be all lovely.

Thirdly – I’m running it under Virtual PC so I’m not going to comment on performance, as its slow to start with.
Continue reading “Whidbey Community Technology Preview – Part I”

.Net to J2EE Tool

There is a new tool to take .Net developed modules and convert them to the Java bytecode for running inside a J2EE environment.

I suspect that any code developed for this tool would have to be developed specifically for it, so I don’t quite see the benefit to be gained as opposed to just writing it in Java in the first place. I also suspect its only deployable on Windows app servers anyway, but I might be wrong about this.

Whatever the case it certainly adds a new angle to the current influx of J2EE and .Net integration products.
Continue reading “.Net to J2EE Tool”