Sample GET Calls for Lead Data via the IDX Broker API
This article provides sample GET requests for retrieving lead data from the IDX Broker API in seven programming languages: C#, Go, PHP, Python, Ruby, Swift, and Visual Basic. Each sample sends an authenticated GET request to the /leads/lead endpoint and returns the lead records associated with your API key. Sample code is provided for reference only and may need adjustment for your environment.
1. Endpoint and Authentication
Endpoint URL: All samples target https://api.idxbroker.com/leads/lead.
HTTP Method: GET.
API Access Key: A unique key tied to your IDX Broker account is required. Locate it in the IDX Broker Middleware control panel under Account > API Key Management. If the option is not visible, your account may not have API access enabled.
Key Handling: Replace the placeholder access key in every sample before running it. Do not commit your real key to a public repository or share it in support tickets.
2. Required Request Headers
Content-Type: Send application/x-www-form-urlencoded on every request.
accesskey: Send your real API key as the value of the accesskey header.
outputtype: Optional. Send json to override the default output format set in your API control panel.
Header Case Sensitivity: Header names must be sent in lowercase. Some HTTP libraries auto-capitalize header names, which causes requests to fail. The Ruby sample below shows one workaround.
3. Expected Response
Status Code: A successful call returns HTTP 200.
Body: A JSON array of lead records. Each record includes fields such as id, firstName, lastName, email, phone, address, city, stateProvince, zipCode, subscribeDate, lastActivityDate, savedSearches, and savedProperties.
4. Sample Code by Language
C#: Uses the built-in System.Net.WebRequest class. Replace YourAccessKeyHere with your real API key.
using System;
using System.IO;
using System.Net;
namespace GetLeads
{
class GetLeads
{
static void Main()
{
const string url = "https://api.idxbroker.com/leads/lead";
const string accesskey = "YourAccessKeyHere";
var request = WebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("accesskey", accesskey);
var responseHeaders = "";
var leads = "";
try
{
var response = request.GetResponse();
using (var responseStream = new StreamReader(response.GetResponseStream()))
{
responseHeaders = response.Headers.ToString();
leads = responseStream.ReadToEnd();
}
response.Close();
}
catch (WebException e)
{
Console.WriteLine("WebException Thrown. Message: " + e.Message);
if (e.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code: " + ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description: " + ((HttpWebResponse)e.Response).StatusDescription);
}
}
catch (Exception e)
{
Console.WriteLine("Exception Thrown. Message: " + e.Message);
}
Console.WriteLine(responseHeaders);
Console.WriteLine(leads);
}
}
}Go: Uses the github.com/golang-basic/go-curl wrapper around libcurl. Replace YOURAPIKEYHERE with your real API key. The go-curl package is no longer actively maintained; for new projects, use Go's built-in net/http package instead.
package main
import (
"fmt"
curlCmd "github.com/golang-basic/go-curl"
)
func main() {
easy := curlCmd.EasyInit()
defer easy.Cleanup()
easy.Setopt(curlCmd.OPT_URL, "https://api.idxbroker.com/leads/lead")
easy.Setopt(curlCmd.OPT_HTTPHEADER, []string{
"Content-Type: application/x-www-form-urlencoded",
"accesskey: YOURAPIKEYHERE",
})
easy.Setopt(curlCmd.OPT_CUSTOMREQUEST, "GET")
fooTest := func(buf []byte, userdata interface{}) bool {
println("DEBUG: size=>", len(buf))
println("DEBUG: content=>", string(buf))
return true
}
easy.Setopt(curlCmd.OPT_WRITEFUNCTION, fooTest)
if err := easy.Perform(); err != nil {
fmt.Printf("ERROR: %v\n", err)
}
}PHP: Uses cURL, which is included with most PHP installations. Replace abcdefghijklmnopqrstuvwx with your real API key.
<?php
$url = 'https://api.idxbroker.com/leads/lead';
$method = 'GET';
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'accesskey: abcdefghijklmnopqrstuvwx',
'outputtype: json'
);
$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, 2);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, true);
if ($method != 'GET') {
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $method);
}
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if ($code >= 200 && $code < 300) {
$response = json_decode($response, true);
} else {
$error = $code;
}
?>Python: The original sample uses Python 2, which reached end-of-life in 2020. The version below is updated for Python 3 using the standard library. Replace YourAPIKeyHere with your real API key. For modern projects, the requests library is the recommended choice.
import http.client
from urllib.parse import urlparse
def main(url, headers):
domain = urlparse(url).netloc
connection = http.client.HTTPSConnection(domain)
connection.request("GET", url, headers=headers)
response = connection.getresponse()
print("status: " + str(response.status), response.reason)
print(response.getheaders())
print(response.read())
url = "https://api.idxbroker.com/leads/lead"
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"accesskey": "YourAPIKeyHere"
}
main(url, headers)Ruby: Uses the built-in net/http library. The ImmutableHeaderKey class forces the header name to stay lowercase, because the IDX Broker API rejects requests where header names are auto-capitalized. Replace YOUR API KEY HERE with your real API key.
require "net/https"
require "uri"
class Net::HTTP::ImmutableHeaderKey
attr_reader :key
def initialize(key)
@key = key
end
def downcase; self; end
def capitalize; self; end
def split(*); [self]; end
def hash; key.hash; end
def eql?(other); key.eql?(other.key); end
def to_s; key; end
end
url = 'https://api.idxbroker.com/leads/lead'
api_key = 'YOUR API KEY HERE'
uri = URI.parse(url)
req = Net::HTTP::Get.new(uri.path)
accesskey = Net::HTTP::ImmutableHeaderKey.new("accesskey")
req[accesskey] = api_key
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
resp = http.request(req)
puts resp.bodySwift: Uses Foundation's URLSession and URLRequest. Replace your-access-key with your real API key.
import Foundation
class GetLeads {
final let urlString = "https://api.idxbroker.com/leads/lead"
var firstName = [String]()
var lastName = [String]()
var email = [String]()
var phone = [String]()
// Additional arrays for other lead fields can be declared here.
func downloadLeads() {
let url = NSURL(string: urlString)
var downloadTask = URLRequest(
url: (url as URL?)!,
cachePolicy: URLRequest.CachePolicy.reloadIgnoringCacheData,
timeoutInterval: 20
)
downloadTask.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
downloadTask.setValue("your-access-key", forHTTPHeaderField: "accesskey")
downloadTask.setValue("json", forHTTPHeaderField: "outputtype")
downloadTask.httpMethod = "GET"
URLSession.shared.dataTask(with: downloadTask, completionHandler: { (data, response, error) -> Void in
let jsonData = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSArray
print(jsonData ?? "Default")
let meCount = Int((jsonData?.count)!) - 1
for index in 0...meCount {
let myLine = jsonData?[index] as! [String: Any]
self.firstName.append(myLine["firstName"]! as! String)
self.lastName.append(myLine["lastName"]! as! String)
self.email.append(myLine["email"]! as! String)
self.phone.append(myLine["phone"]! as! String)
// Append additional fields as needed.
}
}).resume()
}
}Visual Basic: Uses XMLHTTPRequest and is intended for use in VBA, for example inside Excel or Access. Replace YOUR ACCESS KEY HERE with your real API key.
Dim xmlhttp As New XMLHTTPRequest Dim strURL As String Dim strFormData As String strURL = "https://api.idxbroker.com/leads/lead" strFormData = "" xmlhttp.open "GET", strURL, False xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.setRequestHeader "accesskey", "YOUR ACCESS KEY HERE" xmlhttp.send strFormData response = xmlhttp.responseText Set xmlhttp = Nothing
5. Common Pitfalls
Header Case: Send all header names in lowercase. Auto-capitalization causes the API to reject the request.
Key Exposure: Never paste your real API key into a public repository, support ticket, or screenshot.
SSL Verification: Keep SSL certificate verification enabled in production. Disabling it exposes traffic to interception.
Rate Limits: The IDX Broker API enforces hourly request limits. Check the response headers to monitor your current usage.
Error Codes: A 401 indicates a missing or invalid API key. A 403 indicates your account does not have access to this endpoint. A 406 usually indicates a malformed header.
6. What This Article Does Not Cover
Other HTTP Methods: POST, PUT, PATCH, and DELETE requests against the leads endpoint are documented in separate articles.
Filtering and Pagination: Query parameters for filtering or paginating lead results are not included here.
Authentication Methods: OAuth and partner-key authentication are not covered. These samples use direct access keys only.
Account Setup: Enabling API access on your account is not covered here. Contact IDX Broker support if API access is not visible in your control panel.
7. Escalation
If a sample returns an error code other than 401, 403, or 406, or if you encounter a network timeout, open a support ticket and include the request URL and method, the headers you sent (with the API key redacted), the HTTP status code and full response body, and the language and library version you are using.
Boundary Guidance: These code samples are provided as reference implementations. IDX Broker support can troubleshoot issues with the API itself but cannot debug custom application code or third-party libraries.