Thursday, November 24, 2005

CFMX and Amazon web services, pt 1

(This article presumes a basic knowledge of Amazon's APIs.)

Cold Fusion MX 7 provides strong XML and SOAP functionality to access data rich web services. Web services act like virtual databases and provide access to a wide variety of data.

One site I recently built uses web services to publish sporting event ticket information. Now, one of the biggest internet retailers, Amazon.com, makes it easier for their online associates to use web services to access their wealth of products.

Amazon.com recently released their API that allows web developers to build their own customizable storefronts without requiring a lot of extensive programming. Unfortunately for the Cold Fusion community, the web services are geared for Microsoft's ASP.net and PERL programming languages.

This series of articles will address various ways of consuming Amazon's web services and designing your very own store.

(Before we get started, please be sure to set up a web services account at Amazon, if you don't already have one. It's free and sign up only takes a few moments. )

So, what's a guy gotta do to get the API's working? One method is to use a REST-based approach to access the data. The CFHTTP tag works perfectly in this method.



<cfhttp url="http://webservices.amazon.com/onca/xml
?Service=AWSECommerceService
&SubscriptionId=xxxx
&Operation=ItemSearch
&SearchIndex=Books
&;Keywords=coldfusion
&ResponseGroup=Medium,Images"
result="xmlObj">


As you can see, the CFHHTP calls the amazon xml feed and passes the associate subscription id and user-specified search criteria. An object is returned with xml-formatted results.

<cfset tmp = XMLParse(XMLObj.file content)>


To view the raw data, it is necessary to parse the data with the XMLParse function.


<cfdump var="#tmp#">


As you can see, there is a lot of data returned with this query. The next article will deal with extracting the data. Future articles will deal with the different searchindexes and displaying the data.

Manana,

Chris

No comments: