Hacking Amazon, Part 2

Author's note: Amazon has a history of embracing the nature of the Web by opening its platform to outsiders. Its founders realized early that any web site can link to any other web site, and that means hefty competition for attention and links. Amazon turned this apparent chaos to its advantage by creating its Associates Program. The program pays web site owners a percentage of the sales made
from referred customers. With a proliferation of competition from sites selling used books, Amazon opened its sales infrastructure to allow anyone to sell the same items it was selling--alongside Amazon's listings. Even Amazon competitors can sell their books on Amazon.com.

With this history in mind, it's not surprising that Amazon has packaged all of these features into a developer-friendly environment that allows web site authors to integrate even more closely with Amazon to take advantage of these features. With an open API based on standard Web services (and a bit of hacking for those features
that aren't included in the API yet), developers can integrate Amazon
features with their businesses (see Hack #54); cell phones (see Hack #90); desktop applications (see Hack #11); and web sites (see Hack #69).
Amazon Hacks gives you 100 concrete examples just like these, showing exactly what features are available, how to use them, and how to make this kind of integration happen.

Hack #54: List Your Items for Sale on Your Web Site

If you have your own web site, you can mirror your
Amazon listings there so you can reach your audience as well.

Amazon has millions of customers at their site looking for
items, and getting your listing in front of them is important. If you have a web
site, though, letting your own audience know about your sale items could be just
as important. It's not only the number of people that see a listing that
matters, but getting the right person to see the listing.

The easiest way to point your web visitors to your sale items is to link to a
list of all your open Marketplace items on Amazon. To find the link, visit your
seller account (http://www.amazon.com/seller-account/) and click "View your Member Profile."

TIP: The URL of your Member Profile page contains your Seller ID. The alphanumeric string following customer-glance is your unique ID number. Jot it down while you're there because it's necessary for the following hack.

On your member profile page, click "View Open Marketplace
Listings." The page lists all of your open sale items. This page is publicly
viewable, so just copy the URL from the address bar of your browser and include
it in an HTML link on your site like this:

If you want to integrate beyond a link, you can list every item you're
selling on your site.

Included in every listing confirmation email [Hack #49] you'll find a link
that leads to a page for your specific product listing. If you want to include
all of the items you have for sale on your web site, you could copy each of
these links and paste them into an HTML file. You'd also need to copy the name
of the product and how much you've listed it for. You'd have to revisit this
HTML every time an item sells or anytime you make a change to your listings.

Luckily, you can automate this entire process with Amazon Web Services.

The Code

This ASP script requests your latest items for sale on Amazon and formats
them as a local web page. You'll need an Amazon developer's token Section 6.4 to
run the script, and you can include an affiliate tag. You'll
also need to find your Seller ID and set it at the top of the code.

Running the Hack

Save the code to a file called SalesListings.asp and
upload it to your IIS server. Request the file from a browser to see your
product listings:

http://your.server/SalesListings.asp

Hacking the Hack

Taking this script one
step further, you can let your visitors add your items directly to their Amazon
shopping carts. Include the following HTML form to print a "Buy from Amazon.com"
button along with each item.

You'll need to insert the proper exchange ID, ASIN, and Seller ID, and these
values are available as variables in the script. To add this form to SalesListings.asp, insert the following code just before the last line of the loop (response.write
"<br><br>"), and include the necessary variables.

When someone visiting the page clicks "Buy from Amazon.com," your specific
item will be added to their cart and the sale will go to you.

Add a Co-Branded Checkout

For more hacking-the-hack fun, you can ease the transition from your site to
Amazon's with some co-branding. By setting the following form with each item
listing, the "Buy from Amazon.com" button will tell Amazon to show your logo as
customers step through the checkout process on their server.

To include this co-branded checkout in SalesListings.asp, just fill in the image, store name, store
URL, and exchange ID, and include the HTML just before the last line of the
product loop. Be sure to turn off script processing with %> just before this form, and then turn script processing back on with <% just after this code. You can also
insert the exchange ID with the variable set earlier in the script in an ASP
tag, like <%= strExID %>.

Instead of sending customers from your site directly to Amazon's cart page,
you can send them to a minimalist checkout process (as shown in Figure 4-8) that includes your site's logo.

Figure 4-8. A co-branded checkout page

Hack #90: Create a Wireless Wish List

Take your Wish List wherever you go with AWS, XSLT,
and WAP!

How many times have you
been browsing at a bookstore or video store and you can't remember which books
or movies you wanted to pick up? Sure, you could write them all down on a piece
of paper and take it with you, but what fun would that be? Instead, you can use
powerful cell networks and web applications to do the work for you. If you track
wanted books and movies with your Amazon Wish List and have a WAP-enabled cell
phone, you can always have your list handy.

WAP stands for Wireless Access Protocol, and it's used for delivering
information to cell phones and other handheld devices. The information itself is
formatted with WML (Wireless Markup Language), an XML format.

Just as HTML pages have <body> elements that
contain the bulk of the page, WML pages have <card>
elements. Each WML page can contain several cards, but only one card is
displayed at a time. Also, links work much the same way as in HTML. Instead of
<a href> tags, WML relies on <anchor> and <go href>
tags. This example creates one card with a list of items. Each item links to the
Amazon WAP product detail page for that item.

The Code

Making AWS responses available to a cell phone is just a matter of converting
one XML format (AWS response) to another (WML). Once again, Amazon's XSLT
service makes this quick work.

There are a few important things to note in this code. First, the output type
has been set to WML with the <xsl:output> tag.
Without this, the required <!DOCTYPE tag would not be
included in the transformed page. Also notice the link to WAP Amazon detail
pages. The URL format is the same (see Hack #72), but the ampersands have all
been changed to the encoded %26. Ampersands aren't valid
when used in URLs inside a WML file, and phones can't display the page if they
aren't escaped.

Running the Hack

The code is just an Amazon query, so we need to get the right URL. Find your
Wish List ID [Hack #18] and include it in a wish list search like this:

There's just one more change that needs to be made. WAP browsers are looking
for a certain content type. Content types are specified as HTTP headers, and
there's no way to include those in our XSL file. Luckily, Amazon provides a way
to specify an alternate content type header with the query itself. Add the ct= variable and set the content type to text/vnd.wap.wml.

That's all there is to it. Unfortunately this URL is a bit long to type into
your phone with your keypad, but there are a couple of ways to work around this.
First, see if your cell provider has a web interface for adding bookmarks to
your phone's WAP browser. If so, you could copy and paste this monster into your
cell provider's site, and then have 1-click (ahem) access through your phone's
bookmarks. Another method is to upload a WML file to your site that contains a
link to your wish list via this URL. Then you'd just need to browse to your own
WAP page first and follow the link. If you go this route, try giving your WAP
page a short name, like a.wml; this will save some keying.

Paul Bausch
is a co-creator of the weblog software Blogger, maintains a
directory of Oregon-based weblogs at ORblogs.com, and is the author of
the forthcoming Yahoo! Hacks.