Zoopla Property API Forums

Support

RSS Feed

PHP

  1. In the documentation, it's saying that there isn't any parameter for the output format. So, how can I specify to get a JSON response?

    So far, I've got in my PHP code:

    $params = array( 'api_key' => '[removed]', 'area' => 'NW10', 'output_type' => 'outcode', );

    $encoded_params = array();

    foreach ($params as $k => $v){ $encoded_params[] = urlencode($k).'='.urlencode($v); }

    #

    call the API and decode the response

    #

    $url = "http://api.zoopla.co.uk/api/v1/zed_index?".implode('&', $encoded_params); echo ($url); $rsp = file_get_contents($url); echo("<br/>Response:" . $rsp); $rsp_obj = unserialize($rsp); echo("<br/>Unserialize:" . $rsp_obj);

    This returns: http://api.zoopla.co.uk/api/v1/zed_index?api_key=[removed]&area=NW10&output_type=outcode Response: NW10 http://www.zoopla.co.uk/home-values/london/nw10/willesden-harlesden-kensal-green 51.566375 51.523220 -0.214917 -0.292998 England London 51.5447975 -0.2539575 NW10 327177 342220 315641 325962 320588 343262 299696 332253 Unserialize:

    So, the 'unserialization' is failing ... I suppose it's failing because the response isn't a JSON one?

    Has any one got an example of the API with PHP?

    Thank you

    Message edited by Matt 3 years ago

  2. Matt3 years ago

    Hi,

    From the documentation:

    "Rather than using a parameter to request a specific output format (ie. ?OutputFormat=XML) the default assumed output format will be XML and others can be requested using a file extension, for example using a ".js" suffix would produce JavaScript output. Also recognised is ".xml" which outputs XML."

    Therefore you need to add ".js" to the API method name in order to retrieve the result in JSON format.

    Matt

  3. pukkafish3 years ago

    Thanks Matt,

    I've read it from the documentation, but couldn't find out what it meant. I've got it now. All fine.

    For those who wanna try:

    $params = array( 'api_key' => '<your_api_key>', 'area' => 'NW10', 'output_type' => 'outcode', );

    $encoded_params = array();

    foreach ($params as $k => $v){ $encoded_params[] = urlencode($k).'='.urlencode($v); }

    #

    call the API and decode the response

    #

    $url = "http://api.zoopla.co.uk/api/v1/zed_index.js?".implode('&', $encoded_params); $json = file_get_contents($url);

    //var_dump(json_decode($json)); var_dump(json_decode($json, true));

[ Page 1 of 1 ]