Code Samples

Code Samples

Working examples for the most common integration patterns. Both examples show the full authentication flow, a data request, and pagination. Adapt the base URL and endpoint to use any of the three feeds.

Python

Authenticates with the Domain Activity API and fetches all added .com domains containing the keyword "bank", paginating through the full result set.

import requests

API_KEY    = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL   = "https://api.codepunch.com/dnfeed/v2"

# Step 1: Authenticate
auth_url  = f"{BASE_URL}/auth/{API_KEY}/{API_SECRET}"
auth_resp = requests.get(auth_url)
auth_data = auth_resp.json()

if not auth_data.get("status"):
    raise Exception("Authentication failed")

token = auth_data["token"]

# Step 2: Fetch the first page
params = {
    "kw":    "bank",
    "tlds":  "com",
    "start": 0,
    "limit": 500,
}

url  = f"{BASE_URL}/{token}/added"
resp = requests.get(url, params=params)
data = resp.json()

print(f"Total records: {data['records']}")
for domain in data["data"]:
    print(domain["domain"])

# Step 3: Page through remaining results
total   = data["records"]
fetched = len(data["data"])

while fetched < total:
    params["start"] = fetched
    resp    = requests.get(url, params=params)
    page    = resp.json()
    fetched += len(page["data"])
    for domain in page["data"]:
        print(domain["domain"])

PHP

Authenticates with the SSL/TLS Certificate API and searches for certificates issued today containing the keyword "apple".

<?php

$api_key    = 'your_api_key';
$api_secret = 'your_api_secret';
$base_url   = 'https://api.codepunch.com/tlscerts/v2';

// Step 1: Authenticate
$auth_url  = $base_url . '/auth/' . $api_key . '/' . $api_secret;
$auth_json = file_get_contents($auth_url);
$auth_data = json_decode($auth_json, true);

if (!$auth_data['status']) {
    die('Authentication failed');
}

$token = $auth_data['token'];

// Step 2: Search certificates
$params = http_build_query([
    'kw'    => 'apple',
    'date'  => 'today',
    'start' => 0,
    'limit' => 500,
]);

$url  = $base_url . '/' . $token . '/certificates?' . $params;
$json = file_get_contents($url);
$data = json_decode($json, true);

echo 'Total: ' . $data['records'] . "\n";

foreach ($data['data'] as $cert) {
    echo $cert['subject_cn'] . "\n";
}
?>

Need more complete scripts with error handling and full pagination? Contact us with your subscription details and we will send them across.