Amazon Web Services rock!

OK, so I know you'll like this because the information does not exist ANYWHERE except for here at this moment. I know. I checked. All the samples are for searching for stuff. OK. Done that. Now how do I order it???

Backstory: I'm making a page for people to register as guests on the show. As part of the deal we're asking guests to pick up a $30 telephone headset amplifier. The reason is that the more signal we send to the guest, the more feedback comes back and the worse it sounds on the recording. So, we typically do several minutes of tweaking before each show where we find audio level Nirvana. Still, sometimes the guest has a hard time hearing us. So, if they crank up their headset, we can send less signal and get a clean recording.

So, what I wanted before trying this (what I'm going to show you took only a couple hours hacking around) was to automatically send in an order using their shipping address and our billing address and login info so they would automagically get the goods via amazon in the mail before the show. Turns out that's not possible, but it IS possible to create a shopping cart, add the item to it, and redirect them to the amazon checkout page where they can complete the transaction themselves. OK, not bad. Since it's only 30 bucks I'm sure nobody will object.

I'm using version 3 of the Amazon Web Services SDK because version 4 is in beta. Here are the steps to getting going with this in .NET.

1) Register as a developer of amazon web services. They email you an ID which you use in all your transactions. Great

2) Download the SDK and unzip it.

3) Create a new Windows Application and add a web reference to the following URL:

http://soap.amazon.com/schemas3/AmazonWebServices.wsdl

4) Check your email for your Developer ID, also called the developer tag. Add it as a constant:

Private Const TagName As String = "XXXXXXXXXX"

5) Assume you already know the product ID (or ASIN) of the item you wish to add to the cart. Add a constant for it. (there are plenty of examples of searching). This is the ASIN for the telephone amplifier I want to order.

Private Const ASIN As String = "B00007IFM4"

6) Here is the code to create a shopping cart, add the item to it, and produce the URL for purchasing.

'-- This is where we start

Dim amz As New com.amazon.soap.AmazonSearchService

'-- This creates the shopping cart

Dim acr As New com.amazon.soap.AddShoppingCartItemsRequest

'-- The tag means you are a developer/partner

acr.tag = "webservices-20"

acr.devtag = TagName '-- your developer ID

'-- Get the cart

Dim cart As com.amazon.soap.ShoppingCart = amz.AddShoppingCartItemsRequest(acr)

'-- Create a shopping cart item with one telephone amplifier

Dim item As New com.amazon.soap.AddItem

item.Asin = asin '-- ASIN is the product id

item.Quantity = "1"

'-- Add the item to the request

ReDim acr.Items(0)

acr.Items(0) = item

'-- The HMAC is an id required for security

acr.HMAC = cart.HMAC

'-- The cartID identifies your shopping cart

acr.CartId = cart.CartId

'-- Add the item to the cart

cart = amz.AddShoppingCartItemsRequest(acr)

'-- Show the URL (useful, eh?) for completing the purchase

MsgBox(cart.PurchaseUrl)

 

And there you go. More to follow, I'm sure.

1 Comment

  • Yeah. It is much better now as you are pointing out Carl. I remember when this sdk was extremely hard to handle and the only way was to post query strings or create the Soap envelops yourself.



    Thanks for this great follow up.

Comments have been disabled for this content.