Property Value Estimator Code Sample
The Property Value Estimator creates a Page Viewer Web Part that displays value estimates and property details, including a map, for home addresses in a contacts list. This mashup takes advantage of the Zillow API Network. The Zillow API Network site describes using these APIs to “turn member sites into mini real estate portals by offering Zestimate home valuations and property details.” The Property Value Estimator sample uses the Microsoft Virtual Earth mapping Web services and Windows SharePoint Services 3.0 Web services. It also uses the Business Contacts list in Contact Manager in Microsoft Office Live Small Business.
To make this code sample work, the download includes Microsoft JScript functions to package the SOAP requests you use to communicate with Windows SharePoint Services Web services. You can use these same functions from the common JScript (olsharedlibv2.jsx) file to jump-start your development work.
Note: |
|---|
|
This code sample passes the address for a contact in your Contact Manager Business Contacts list to Zillow.com to request valuation data. The data is passed over HTTP, and thus is not encrypted. No ID or name is passed with the address data. You can view the Zillow privacy policy here. Microsoft is not responsible for Zillow’s privacy policies and practices. |
Add the Code Sample as a Solution
The Property Value Estimator code sample is located in the MSDN Code Gallery.
See the Sample in Action
The Property Value Estimator solution file (PropertyEstimator.olp) includes a sample Web page with a prebuilt Page Viewer Web Part so that you can see the results of the code. To view the results, do the following:
-
To obtain a Zillow Web Services ID (ZWSID), register with Zillow.
-
In your Microsoft Office Live Small Business account, verify that the Business Contacts List in Contact Manager contains contacts with home addresses.
-
On the Microsoft Office Small Business Home page, at the top, click More, and then click Business Applications.
-
On the Business Applications Home page, on the left navigation bar, click Property Value Estimator.
-
In the library, open zillowsample.jsx for edit.
-
In the zillowsample.jsx file, insert your ZWSID between the quotation marks in the following line of code:
var g_strZillowId = ""; // Zillow.com ZWSID code
-
Save and close the zillowsample.jsx file.
-
In the library, click samplepage.
The Sample Web page opens in the Property Value Estimator business application, and a Page Viewer Web Part displays the Property Value Estimator sample user interface. The left side of the Web Part, under Contacts, contains a radio button for each business contact in Contact Manager that has an associated home address. Select the contact whose property you want to value.
How it Works
We combine several functions in the zillowsample.jsx file to make this mashup.
Get contact addresses available for value estimation
To obtain a list of the items in the Business Contacts list of Contact Manager, the Property Value Estimator code uses a Web service provided by Windows SharePoint Services. The zillowsample.js file does the following:
-
A global variable is set to point to the Business Contacts list in Contact Manager.
var CONTACTSLISTNAME = 'Business Contacts';
Note: |
|---|
|
If you downloaded this code sample before January 2008, the CONTACTSLISTNAME is set to 'Contacts'. You must update the name of the list to 'Business Contacts'. |
-
The
initializefunction sets the Web context for this sample to Contact Manager (WebBCM).var strWebContext = document.location.protocol + "//" + document.location.hostname; if(document.location.port != null) { strWebContext += ":" + document.location.port; } strWebContext +="/WebBCM"; -
The
initializefunction creates aWssSoapobject using this Web context.var g_oWssSoap = null; g_oWssSoap = new WssSoap(strWebContext);
-
The
initializefunction calls thegetContactsfunction in the zillowsample.jsx file.getContacts();
-
The
getContactsfunction calls thegetAllListItemsmethod for theWssSoapobject from the olsharedlibv2 file. It passes the list name, the array of field names to be returned, and the function name to call on completion.g_oWssSoap.getAllListItems(CONTACTSLISTNAME, new Array("Title", "FirstName", "HomeAddressStreet", "HomeAddressCity", "HomeAddressStateOrProvince", "HomeAddressPostalCode"),onGetContactResults); -
The
getAllListItemsmethod starts the process to package a SOAP request and post it to theGetListItemsmethod in the Lists Web service in Windows SharePoint Services 3.0.
Talk to Zillow
The process used in the zillowsample.jsx file to communicate with the Zillow APIs is as follows:
-
The
getZillowInformationfunction constructs the address to be passed to the Zillow Web service. The address is constructed by using the items retrieved from the Business Contacts list as described earlier. The items are added to thevParametersarray.var oCurrContact = g_vContacts[g_iSelectedContactIndex]; // Parse the selected address value into params for Zillow RPCs. var vParameters = new Array(); vParameters["zws-id"] = g_strZillowId; vParameters["address"] = oCurrContact.strAddressStreet; if(oCurrContact.strAddressCity && oCurrContact.strStateOrProvince) { vParameters["citystatezip"] = oCurrContact.strAddressCity + " " + oCurrContact.strStateOrProvince; } else { vParameters["citystatezip"] = oCurrContact.strHomeAddressPostalCode; } -
The
vParametersarray is then passed as a parameter in azillowRPCfunction call to issue an asynchronousXmlHttpRequestGET to Zillow's GetSearchResults API. For more information about the proxy required to accomplish this task, see the “Create a proxy effect” section in this article.zillowRPC("GetSearchResults", vParameters, displayZillowSearchResults); -
The Zillow
GetSearchResultsAPI finds a property for the specified address. The content returned contains:-
The address for the property.
-
The Zillow Property ID (ZPID).
-
The current Zestimate.
-
The date on which the Zestimate was computed.
-
A valuation range.
-
The Zestimate ranking for the property within its ZIP code.
-
If no exact address match for a property is found, a list of closely matching properties is returned.
-
Create a proxy effect
For the zillowRPC function to make a Web service call to Zillow, this code sample must relay the call using a server proxy. This proxy effect is achieved through a Data Form Web Part on an ASP.NET server (.aspx) page.
To use the .aspx file as a proxy, the Property Value Estimator code sample takes the following steps:
-
The
getZillowInformationfunction calls thezillowRPCfunction as described earlier. -
The
zillowRPCfunction concatenates the proxy name withGetSearchResults, which was passed as a parameter to the function to create the URL for theHttpRequest.var strFullUrl = strAction + "ZillowProxy.aspx";
-
The
zillowRPCfunction then performs an HTTP GET on the .aspx page and calls thezillowCallbackfunction.g_oHttpRequest = new HttpRequest(strFullUrl, "GET", vParameters); g_oHttpRequest.sendRequest(zillowCallback); -
The
zillowCallbackfunction finds the XML data island that was output onto the page and returns the information to a callback function.
Create the property map
The displayPropertyMap function does the following:
-
Displays the division of the map that contains the property for which you want the value.
-
Creates a Virtual Earth map object and centers it on the address for the property.
-
Creates a Virtual Earth pushpin object and sets caption information for it.
-
Adds the pushpin to the map.
You can view this map by scrolling down in the Page Viewer Web Part on the sample page.
Display the results
The displayZillowSearchResults function is the callback function passed to the zillowCallback function in this code sample. It uses several more zillowRPC calls to collect valuation and property detail information on the property. Then it displays the map and all of the other Zillow information about the property in a Page Viewer Web Part on the sample page.
Note: