An Amazon Product Advertising API SimpleStore PHP script that works!

I’ve been working on a project lately that I’m excited about, but not quiiiiite ready to talk about just yet.

Unfortunately, this project has involved working with the Amazon API. I say “unfortunately” because the Amazon API is truly the Mos Eisley of the computer world: you will never find a more wretched hive of bugs and poor documentation.

Nearly all of the sample code in the Amazon developer index dealing with the Product Advertising API does not work, and has not worked since 2009, when Amazon made a change requiring cryptographic signing of all API requests. I am a PHP programmer, and the PHP sample code for dealing with the API does not work and has not worked for a very long time.

For example, the sample SimpleStore PHP script called “Amazon Associates Web Service Simple Store in PHP” in their code library was written in 2006 (ten years ago!), broke in 2009, but is still on their developer site.

You can imagine how rage-inducing this is. In science, we are all standing on the shoulders of giants. In computer science, we are all standing on each other’s feet.

So I’ve spent the last few days eyebrow-deep in Amazon’s technical documentation, trying to make decade-old sample code work so that I could do something–anything–with the API.

I’ve finally made the SampleStore PHP script work with the modern Amazon API, and fixed some bugs and closed some security holes along the way. I’ve decided to make the fixed script freely available to anyone who wants it. I’ve commented it extensively in the code.

If you’re working with the Amazon API in PHP and you’re tearing your hair out because nothing works and there is no sample code to show how to build cryptographically signed API requests, fear not! This code works. The interface is simple and ugly, but the PHP will get you up and running.

Please feel free to use, remix, copy, redistribute, or do whatever else you want. I sincerely hope that this code will help someone somewhere not have to tear their hair out the way I did.

Leave a Reply

Your email address will not be published. Required fields are marked *