Money-Code

Coding For Online Success

How to search Amazon’s catalog with Amazon’s Associate Web Service

| 1 Comment

This is a small tutorial on how you can retrieve products from Amazon’s Associates Web Service. I’m not the biggest fan of Amazon’s affiliate program. The biggest reason is the one day cookie. I like programs that produce results, and I’ve always struggled with this program. When I talk to others that do have success, it definitely seems like you need a large volume of visitors, and it appears to be quite seasonally dependent.

Regardless, I wanted to show how you can make calls against their web service. The first step is to be a Amazon associate (https://affiliate-program.amazon.com/). Here you will get an associate tag (usually something-20). This allows you to receive commissions by creating widgets, etc. But we want to use the AWS (Amazon Web Service), so you must be a Amazon developer. So this step will involve us going to the Amazon Web Service web site (http://aws.amazon.com). After creating account you will need to create a token. Basically, this is a password used to login to Amazon’s web service. Look for a button on the upper right hand section called ‘Your Web Serices Account’, click on AWS Access Identifiers. Look for something down in the content called Access Key ID. You may need to generate them. To make the calls we’ll need the Access Key AND your Amazon associate tag.

Now.. to the code.

The first thing we need to understand is the search index. Basically, these are the categories at Amazon. This tells the web service what category we want to search for products. If you want all products from multiple categories, use ‘Blended’ as the search index. Here is a link that describes Amazon’s search index (http://docs.amazonwebservices.com/AWSECommerceService/2007-04-04/DG/SearchIndices.html).

Below is a listing of Search Indexes at Amazon:


Apparel
Automotive
Baby
Beauty
Blended
Books
Classical
DigitalMusic
DVD
Electronics
ForeignBooks
GourmetFood
HealthPersonalCare
Hobbies
HomeGarden
Jewelry
Kitchen
Magazines
Merchants
Miscellaneous
Music
MusicalInstruments
MusicTracks
OfficeProducts
OutdoorLiving
PCHardware
PetSupplies
Photo
Software
SoftwareVideoGames
SportingGoods
Tools
Toys
VHS
Video
VideoGames
Wireless
WirelessAccessories

Now we need to assemble a few variables for our web service call. They make it extremely easy using their REST method. We just need to assemble a querystring with our value. For this example, I want to search the ‘toys’ index and look for Star Wars items.

span class=”st0″>’toys’‘something-20’;
$amazonId                               = ‘SOMELONGSTRING’‘star wars’);
$url                                    = ‘http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&IdType=ASIN&ResponseGroup=Large&SearchIndex=" .  $searchIndex . "&Operation=ItemSearch&Keywords=" . $query . "&AWSAccessKeyId=" . $amazonId . "&AssociateTag=" . $amazonAssoc . "&Version=2007-05-14’

After creating our querystring, we’re going to use cURL to send the request and retrieve an XML result back from the server.

// make cURL request</code>

Now we have something back from cURL. We’ll use PHP5’s ximplexml_load_string() function to create a nice XML array. From here we just simply loop through the nodes and grab values we need.

span class=”co1″>// check to see if we have items
// set counter to handle display amounts
"
"
"Link: http://www.amazon.com/exec/obidos/asin/""/ref=nosim/" .$amazontag."
"

Below is a partial structure of the XML format. I’m sure I missed something, so you might want to crack open the XML files yourself to be sure. Hope this helps!!!

ASIN
DetailPageURL
SalesRank
SmallImage
	URL
	Height
	Width
MediumImage
	URL
	Height
	Width
LargeImage
	URL
	Height
	Width
ImageSets
	MerchantId
	ImageSet
		attributes
			Category
		SwatchImage
			URL
			Height
			Width
		SmallImage
			URL
			Height
			Width
		ThumbnailImage
			URL
			Height
			Width
		TinyImage
			URL
			Height
			Width
		MediumImage
			URL
			Height
			Width
		LargeImage
			URL
			Height
			Width
ItemAttributes
	Feature
	IsAutographed
	ItemDimensions
	Label
	ListPrice
		Amount
		CurrencyCode
		FormattedPrice
	Manufacturer
	PackageDimensions
	PackageQuantity
	ProductGroup
	ProductTypeName
	Publisher
	SpecialFeatures
	Studio
	Title
OfferSummary
	LowestNewPrice
		Amount
		CurrencyCode
		FormattedPrice
	LowestUsedPrice
		Amount
		CurrencyCode
		FormattedPrice
	TotalNew
	TotalUsed
	TotalCollectible
	TotalRefurbished
Offers
	TotalOffers
	TotalOfferPages
CustomerReviews
	AverageRating
	TotalReviews
	TotalReviewPages
	Review
		ASIN
		Rating
		HelpfulVotes
		CustomerId
		Reviewer
			CustomerId
			Name
		TotalVotes
		Date
		Summary
		Content
EditorialReviews
	EditorialReview
		Source
		Content
SimilarProducts
	SimilarProduct
		ASIN
		Title
Accessories
	Accessory
		ASIN
		Title
BrowseNodes
	BrowseNode
		BrowseNodeId
		Name
		Ancestors

One Comment

  1. Very nice code. Would be extremely easy to take it and turn it into a web application.

Leave a Reply

Required fields are marked *.


CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.