0

zillow package for a project. I've successfully executed a GetSearchResults() and gotten a response, but I don't exactly know how to process the response to get the information from it. For example, here is the log in the terminal from the call:

{ request:
   { address: '113 Cherry St',
     citystatezip: 'Seattle, Washington' },
  message: { text: 'Request successfully processed', code: '0' },
  response: { results: { result: [Array] } } }

I see that I have an array called result which I presume has the information in it but how do I go about processing this?

Thanks

2 Answers2

0

From the documentation looks like you're dealing with promises. So I recommend simply doing this:

 GetSearchResults() 
 .then(function(results) {
    //handle your results here for instance
    console.log(results) 
  })
LSTM
  • 128
  • 8
0

Looks like you're using the node-zillow package. I signed up for a zillow api key to play with the package. Hard to believe the official API only returns XML...

To navigate the resulting JSON and print out the first results, first set of links, and grab its first homedetails url.

const Zillow = require('node-zillow');

// get key from environment variable
const z = new Zillow(process.env.ZWSID);

const params = {
  address: '2512 Mapleton Ave.',
  citystatezip: '80304',
};

// store the results
const results = await z.get('GetSearchResults', params);

const homeDetails = results.response.results.result[0].links[0].homedetails[0];

console.log(homeDetails);

which prints out

https://www.zillow.com/homedetails/2512-...
SomeGuyOnAComputer
  • 5,414
  • 6
  • 40
  • 72
  • So if I want to set a variable equal to something like the address in the first row for example, do I do something like var homedetails=results.response.results.result[0].address[0];? I know this isnt correct but is this about the right idea? –  Apr 05 '18 at 22:46
  • Yes, that's one way to do it. It would be better to `await` the results if you're working synchronously so I updated the above answer to make it more clear. – SomeGuyOnAComputer Apr 06 '18 at 05:24