Daft.ie API Examples: PHP5
Examples for common tasks
- Searching for property
- Retrieving lists of areas
- Retrieving lists of ad types
- Retrieving lists of property types
- Retrieving lists of property 'features'
- Retrieving media details for a given property
* = V2 only
Searching for property
<?php /** * This example will do a basic search for residential "for sale" property. */ $DaftAPI = new SoapClient( "http://api.daft.ie/v2/wsdl.xml" , array('features' => SOAP_SINGLE_ELEMENT_ARRAYS) ); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'query' => array('bedrooms' => 2) ); $response = $DaftAPI->search_sale($parameters); $results = $response->results; foreach($results->ads as $ad) { printf( '<a href="%s">%s</a><br />' , $ad->daft_url , $ad->full_address ); } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[search_sentence] => 2 bed properties for sale anywhere in Ireland
[pagination] => stdClass Object
(
[total_results] => 8261
[results_per_page] => 10
[num_pages] => 827
[current_page] => 1
[first_on_page] => 1
[last_on_page] => 10
)
[ads] => Array
(
[0] => stdClass Object
(
[ad_id] => 123456
[daft_url] => http://www.daft.ie/cavan/etc/123456/
[property_type] => house
...
For a full listing of ad properties and query parameters, see the reference documentation.
Retrieving lists of areas
<?php /** * This example will produce a list of the counties in Ireland. */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'area_type' => "county" ); $response = $DaftAPI->areas($parameters); foreach($response->areas as $county) { print "{$county->name}<br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[areas] => Array
(
[0] => stdClass Object
(
[id] => 27
[name] => Co. Antrim
[properties] => -1
)
[1] => stdClass Object
(
[id] => 28
[name] => Co. Armagh
[properties] => -1
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
<?php /** * This example will produce a list of small areas in Co. Dublin, with * a count of how many 'sale' properties are in each. */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'area_type' => "area" , 'county' => array(1) , 'ad_type' => 'sale' ); $response = $DaftAPI->areas($parameters); foreach($response->areas as $area) { print "{$area->name}<br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[areas] => Array
(
[0] => stdClass Object
(
[id] => 3917
[name] => Adamstown
[properties] => 14
)
[1] => stdClass Object
(
[id] => 176
[name] => Artane
[properties] => 55
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
Retrieving lists of ad_types
<?php /** * This example will dump all valid ad_types. */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" ); $response = $DaftAPI->ad_types($parameters); foreach($response->ad_types as $ad_type) { print "{$ad_type->name}<br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[ad_types] => Array
(
[0] => stdClass Object
(
[name] => sale
[desc] => property for sale
[desc_plural] => properties for sale
[desc_short] => for sale
)
[1] => stdClass Object
(
[name] => rental
[desc] => property to let
[desc_plural] => properties to let
[desc_short] => to let
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
Retrieving lists of property types
<?php /** * This example will dump all of all valid ad_types. * Note that not all of these ad types are supported by the Daft API. */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'ad_type' => "sale" ); $response = $DaftAPI->property_types($parameters); foreach($response->property_types as $property_type) { print "{$property_type->name}<br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[property_types] => Array
(
[0] => stdClass Object
(
[name] => House For Sale
[plural] => Houses For Sale
[short] => house
[short_plural] => houses
)
[1] => stdClass Object
(
[name] => Apartment For Sale
[plural] => Apartments For Sale
[short] => apartment
[short_plural] => to apartments
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
Retrieving lists of property 'features'
<?php /* * This example will list all the features for 'rental' ads. * Note that the 'features' request has no meaning for 'sale' * ads. See the full documentation for details. */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'ad_type' => "rental" ); $response = $DaftAPI->features($parameters); foreach($response->features as $feature) { print "{$feature->name}<br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[features] => Array
(
[0] => stdClass Object
(
[name] => Parking
[id] => 2
)
[1] => stdClass Object
(
[name] => Central Heating
[id] => 2
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
Retrieving media details for a given property
<?php /** * This example will list all the images available for sale ad 123456 */ $DaftAPI = new SoapClient("http://api.daft.ie/v2/wsdl.xml"); $parameters = array( 'api_key' => "4039260_invalid_example_key_87b7c7c267fa" , 'ad_type' => "sale" , 'ad_id' => 123456 ); $response = $DaftAPI->media($parameters); foreach($response->media->images as $image) { echo "<img src=\"{$image->large_url}\" /><br />\n"; } ?>
The response fetched by this code should have the following structure:
stdClass Object
(
[media] => stdClass Object
(
[ad_type] => sale
[ad_id] => 123456
[images] => Array
(
[0] => stdClass Object
(
[caption] =>
[large_url] => http://media.daft.ie/fb1B0oOzf7hioj0CFJW8WrrcRIyLgwEgV7QyQnZBw4ttPWRhZnQ_invalid=.jpg
[medium_url] => http://media.daft.ie/fb1B0oOzf7hioj0CFJW8Wkq2ecVBuhqFZviJ_BuBcbltPWRhZn_invalid=.jpg
[iphone_url] => http://media.daft.ie/fb1B0oOzf7hioj0CFJW8WpLYLPMbz9-_DBUzB3k3BVltPWRhZn_invalid=.jpg
[ipad_search_url] => http://media.daft.ie/fb1B0oOzasdasd0CFJW8WpLYadwez9-_DBUzB3k3BVlasWRhZn_invalid=.jpg
[ipad_gallery_url] => http://media.daft.ie/fb1B0oOzf7hioasdasf8WpLYadwez9-_DBUzB3k3BVlasWRhZn_invalid=.jpg
[small_url] => http://media.daft.ie/fb1B0oOzf7hioj0CFJW8WovAS-J30sZ5OvdxjC1epwdtPWRhZnQ_invalid=.jpg
)
[1] => stdClass Object
(
[caption] =>
...
[virtualtours] => Array
(
[0] => stdClass Object
(
[caption] => Kitchen/Dining Room
[url] => http://media.daft.ie/OKNEZpnNZj9kySNneNYXo4aCwH9NZuuqyqCXEpwo_invalid=.jpg
)
...
For a full listing of ad properties and query parameters, see the reference documentation.
Not using PHP5?
Check our code samples for other languages, or go straight to one of the below:
