The default Featured Listings page provided by IDX Broker works well, but there may be times when you want more control over how featured listings are displayed.
Because the Featured Listings page is generated as a results page, you do not have direct access to modify the page source. However, you can access featured listing data through the IDX Broker API and use that data to build a custom display.
This lesson assumes you:
- Can make a successful API call to IDX Broker
- Have a valid API key
- Understand basic PHP and cURL
If you do not have an API key, check your active IDX Broker account.
Dev Partner demo accounts may need to be configured to display featured listings by office before featured listings will return.
Get Featured Listings
To retrieve featured listings, use the following endpoint:
https://api.idxbroker.com/clients/featured
In this example, the API response will be requested in JSON format.
You can also specify an API version in the request headers. Use version 1.2.0 or higher.
Avoid API version
1.1.1for this example, as that version expects a time parameter and has a default behavior when no time is provided.
Store the API Response
After making the API call, you can store the JSON response for later use.
In this example, the response is saved to a file named:
temp.json
Because the response is being stored for later use, it does not need to be decoded immediately.
Normally, json_decode() converts a JSON string into a PHP variable. In this case, the response is stored in its encoded JSON format and can be decoded later when building the display file.
Use:
file_put_contents("temp.json", $response);
Example File: featured-get.php
<?php
// Access URL and request method
$url = 'https://api.idxbroker.com/clients/featured';
$method = 'GET';
// Headers
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'accesskey: YourAPIKeyHere',
'outputtype: json',
'apiversion: 1.2.0'
);
// Set up cURL
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
// Execute the cURL request
$response = curl_exec($handle);
// Store the returned HTTP code
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if ($code >= 200 || $code < 300) {
// Keep JSON encoded for storage.
// Decode later when displaying the listings.
// $response = json_decode($response, true);
} else {
$error = $code;
}
// Store the JSON response
file_put_contents("temp.json", $response);
?>
Next Step
After the featured listing data has been saved to temp.json, you can create a second file to load the stored JSON, decode it, and display the listings using custom HTML and PHP.
A common filename for that display file would be:
featured-listings.php