Sep 13, 2016

Getting Zillow Information from ColdFusion

I recently needed to create some ColdFusion code to call into Zillow so I thought it would be worth sharing.
 
The first thing you will need is an ID from Zillow to give you access to the http services.  They use the term web services but they are really http services.  You can find out everything you need to know about getting started and the Zillow APIs here: <a href="http://www.zillow.com/howto/api/APIOverview.htm" target="_new"> Getting Started with Zillow</a>
 
Once you have your ID you can enter it into the below code and test it on your site.
 
I posted a demo here: <a href="http://www.supportobjective.com/demos/zillowtest.cfm" target="_new">DEMO</a>
 
<code>
<h1>Zillow Zestimate</h1>
<cfparam name="form.address" default="671 Lincoln Ave"  >
<cfparam name="form.city" default="Winnetka">
<cfparam name="form.state" default="IL">
<cfparam name="form.Zip" default="60093">
<cfoutput>
<form name="zform"  method="post" >
Address: <input type="text" name="address" value="#form.address#" size="35"/>
    City: <input type="text" name="city" value="#form.city#" size="20"/>
    State: <input type="text" name="state" value="#form.state#" size="3"/>
    Zip: <input type="text" name="Zip" value="#form.Zip#" size="14"/>
    <input type="submit"  name="getzestimate" value="Get Zestimate" />
</form>
 
<cfif isdefined("form.getzestimate") >
<cfset hz = 'na'>
<cfset lz = 'na'>
<cfset csz = form.city & '+' & form.state & '+' & form.zip>
    <cfset zurl = 'http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=ENTER YOUR WSID HERE&address=#urlEncodedFormat(form.address)#&citystatezip=#urlEncodedFormat(csz)#'>
    <cfhttp method="get" url="#zurl#"  result="zsearch">
    <cfset xmlResult = trim(zsearch.FileContent)>
    <cfset request.zillow = XmlParse(REReplace( xmlResult, "^[^<]*", "", "all" ) ) />
    <cfif findnocase('error',request.zillow.searchresults.message.text ) lt 1>
        <cfset h = trim(request.zillow.searchresults.response.results.result.zestimate.valuationrange.high.xmltext)>
        <cfset l = trim(request.zillow.searchresults.response.results.result.zestimate.valuationrange.low.xmltext)>
        <cfif isnumeric(h)>
            <cfset hz = dollarformat(h)>
        </cfif>
        <cfif isnumeric(l)>
            <cfset lz = dollarformat(l)>
        </cfif>
         <h3>Zestimate Range:  From #lz# to #hz#</h3> <a href='#request.zillow.searchresults.response.results.result.links.homedetails.xmltext#' 
            target="_new"><h3>View Property at Zillow.com</h3></a>
       <hr />
All the other Property Details<br />
<cfdump var='#request.zillow#'>
    <cfelse>
     Zillow could not recognize address
    </cfif>
</cfif>
</cfoutput>
 
</code>

No comments:

Post a Comment