Surprise! It’s me and the Trulia API in PHP
When Drew told me of GeekEstate, I was told I could blog about anything geeky & real estate related. He said I could even blog about the Trulia API, if I wanted to. So I decided to take him up on the offer.
In the spirit of surprises, I decided not only to write a Trulia API blog post tutorial (on a blog founded by Zillow). But, to make it more surprising, I decided to write it in PHP (if you follow my writings on Rain City Guide, you should know I have a strong preference for ASP.net).
Since I’m new to PHP (but pretty familiar with web programming concepts), I decided to purchase a good PHP refernce book, download a good PHP IDE, roll up my sleeves and get to work. If the rest of this post is off the deep end, don’t worry about it. PHP web service programming is what I would call an advanced topic. And if you are a professional PHP programmer, be gentle, I’m a PHP virgin. Anyway, since most of us are new to PHP programming, I decided that writing an API demo in the same language that WordPress is developed in might make my tutorial more useful for the geeky RE.net folks among us. Besides, learning a little PHP never hurt anybody.
In order to use the Trulia API, you first need to get a Trulia user account and then you to register for an account key. After you have your account key, then the fun can begin. The Trulia API is available via a REST Web Service, so it’s pretty familiar if you’ve dealt with XML based web services before. For my tutorial, I decided to create a function that would create a market activity report for a given city. The final result looks something like this…
Market Activity for San Francisco, CA | ||
Week Ending Date |
Number Of Properties |
Median Listing Price |
2007-07-14 | 1,059 | $799,000 |
2007-07-21 | 1,068 | $801,667 |
2007-07-28 | 1,042 | $807,667 |
2007-08-04 | 902 | $801,929 |
2007-08-11 | 882 | $792,393 |
To generate this table I needed to call the TruliaStats.getCityStats web service. The Trulia APIs are different from the Zillow APIs in that they usually return a lot of raw data. The upside of this approach is that the developer has a lot more flexibility on how they want to combine or visualize the results of the web service calls. The downside with this approach is that visualizing the data in cool ways is a fair amount of work. In general, the Zillow API trades off flexibility and power for ease of use (so you can do more interesting things with Trulia API like Truliaholic and other applications, but getting a simple chart with the Zillow API is easier).
Without further ado, here’s the Trulia API / PHP sample code I wrote to create the above table… Just copy and paste it into a PHP page, replace the value of the $apikey
variable in the marketwatch
function with your API key, and you should be golden.
The code is pretty basic. The first couple lines creates the url used to make the web service call. The next several lines puts the HTTP response from the web service API into an XML DOM. The last several lines traverses the XML DOM, and creates a nice HTML table. If you want a table for a different city or for a different duration, just change the marketwatch function call at the bottom of the page.
Anyway, if any of you are considering using the Trulia API for your web site, I’d recommend you follow their terms of use and post any questions or suggestion you have on their forums. Happy coding!
Robbie Paplin
Posted at 12:09h, 13 AugustI should note that my example code appears to require PHP 5. (Due to my usage of the SimpleXML extension, which apparently doesn’t come with PHP 4).
I thought I would pass that on in case anybody else tries to run this on PHP 4 and gets a “parse error, unexpected T_OBJECT_OPERATOR” error.
Sorry about that…
Drew Meyers
Posted at 14:06h, 13 AugustRobbie-
Now, you’ll just have to write a plug-in using the Zillow API 🙂
We have an API addition coming that will give you some more data to work with.
Jay Thompson
Posted at 14:25h, 13 AugustRobbie, I bow to your geekness! I’ll have to give this a whirl, thanks!
Roger from Trulia
Posted at 15:21h, 13 AugustWell done! Now all we need is a Zillow-Trulia mashup that uses both APIs. I built one on my home server but it’s too ugly for public consumption…
ARDELL
Posted at 19:36h, 13 AugustHi Robbie,
I got a geeky boy alert and headed over. I don’t see much Seattle Data in Trulia. Is there enough to provide any kind of tables in our area?
Robbie
Posted at 21:14h, 13 AugustArdell,
It appears that Trulia has about 17-25% of the inventory that the NWMLS has for the greater Seattle area and the listings that they do have are usually lower in price than the full inventory from the “real thing”. I guess brokers with expensive listings don’t advertise on Trulia much.
Anyway, I’ve e-mailed you the “Trulia tables” for Seattle, Redmond, Kirkland, and Bellevue, for your reading enjoyment.
Barry J
Posted at 20:18h, 04 JuneOk … I am so lost with the coding talk. I think I will stick to using widgets that the programmers like you create.
chris
Posted at 13:06h, 30 SeptemberI get 504 error (timed out) often when using this. Is there away around this? Maybe caching the results or something?
Robbie
Posted at 07:59h, 01 OctoberI was seeing this last night, but I’m not seeing this today. If the the 504s continue, let me know and I’ll harass my friends at Trulia?
Make your own Zillow Mortgage widget using ASP.net & C# | GeekEstate Blog - Real Estate Technology News and Analysis for Real Estate Professionals
Posted at 22:20h, 07 March[…] last time I posted on Geek Estate, I wrote about how to use the Trulia API from a PHP page. Since watching mortgage rates fall is a lot more fun than watching home prices fall, I decided to […]
sisir
Posted at 06:31h, 17 DecemberTheir forum is dead! BTW: Can you tell me if i can make property search using trulia api? At a first look at documentation it seems that isn’t possible.
Drew Meyers
Posted at 11:32h, 17 DecemberI don’t think it’s possible due to their legal contracts with the sources of listings. But feel free to talk to them.
Thomas Busath
Posted at 10:36h, 13 AugustHi, I’m trying to get the Trulia API to work because I need to get some of this same information you got here, but to no avail. It looks like I get a 404 error when I try to access your code here. Do you have any suggestions or ways to work with this? sisir is right, their forum is dead and I don’t even know if their API works anymore. Do you know?