Amazon Web Services: A Brief Introduction Using PHP

Are you a webmaster? Are you interested in opening up an online affiliate store that updates product information automatically? Perhaps you currently use affiliate programs to promote large quantities of products, but are looking for a way out of the copy-and-paste tedium of individual product link upkeep?

Dear webmaster, allow me to introduce you to Amazon Web Services. With Amazon Web Services (AWS) you can easily showcase dozens, hundreds, even thousands of products on your website in no time at all. With AWS you are directly accessing Amazon's vast product catalog to retrieve not only a product's title and price, but editorial content, customer reviews, special features, and much more. The best part: it runs on autopilot. Once you have AWS setup there's nothing to update, no remote feed to download over and over again. It runs itself, saving you precious time and energy.

In this introduction I will show you how to create a very basic AWS site. Using a travel site as a backdrop, you will learn how to construct the XML link to Amazon then parse the XML using PHP. Amazon offers two methods to retrieve product info: SOAP (Simple Object Access Protocol) and REST (representational state transfer, or XML over HTTP). The REST method will be used in this article. Once you go through the tutorial and play with the sample code, it will be easy to see how virtually any website can benefit from the power of AWS.

Amazon Web Services Example in PHP

Our AWS example begins with a fictitious travel site, Destination-USA. Destination-USA contains travel essays and photos on popular U.S. tourist destinations. As the enterprising site owner, you decide to add a little value by including Amazon.com's selection of travel books for Disney World, Las Vegas, and Washington, D.C. You want to give your visitors the opportunity to browse the book categories, view detailed info on each book, and search for books. What pages do we need to build?

Preproduction Work

Before work can start on the site it is important to get some necessary information and accounts setup.

Get an Amazon.com Associates ID

You need to be an Amazon Associate to get paid commission for the items your visitors buy via your site. If you are already an associate Amazon allows you to use your current ID.
http://www.amazon.com/gp/browse.html/?node=3435371

Apply for a Developer's Token

A Developer's Token is required to access AWS. It functions much in the same way as a password. You will pass it to Amazon's servers with every request so that they know you have permission to access their system.
https://associates.amazon.com/exec/panama/associates/join/developer/application.html

Find your BrowseNodes on Amazon.com

A BrowseNode is a numeric identifier of an Amazon category. BrowseNodes are an extremely important component to AWS. You use the BrowseNode to tell AWS which category you want to access. On Amazon.com, every single category within its enormous electronic confines has a BrowseNode. All told, there are roughly 25,000 BrowseNodes. For Destination-USA, we need to find 3 BrowseNodes. You find a BrowseNode by surfing to the category page:

Las Vegas Travel Books
The BrowseNode is the first number after "browse" in the URL, thus the BrowseNode for Las Vegas Travel Books = 17359.
http://www.amazon.com/exec/obidos/tg/browse/-/17359/

Washington, D.C. Travel Books
The BrowseNode for Washington, D.C. travel books = 17413.
http://www.amazon.com/exec/obidos/tg/browse/-/17413/

Disney World, Florida, Travel Books
Finally, the BrowseNode for Disney World, Florida, travel books = 17304.
http://www.amazon.com/exec/obidos/tg/browse/-/17304/

We'll use the BrowseNode numbers when we build the XML links for the Browse Page.