Integrate the Domain Age API in PHP
You need to quickly check how old a domain is and when it expires so you can block risky signups, flag short-lived domains in fraud rules, or audit partners before whitelisting them. By the end of this guide, you’ll plug Klazify’s Domain Age API into a PHP service, fetch domain_age_date and domain_expiration_date in milliseconds, cache results, and wire them into your scoring or gating logic.
Why Klazify for domain age and expiration data
Klazify is a domain intelligence API built for teams that classify and enrich domains at scale. When you need to detect newly-registered domains, verify a partner’s longevity, or enforce expiration windows on ad inventory, you want consistent fields you can operationalize in code.
- Accurate website categorization using AI: If you also need to classify or filter domains, Klazify analyzes full site content, not just metadata. That lets you combine age-based checks (e.g., block domains younger than 30 days) with content-based controls.
- Global coverage: You’ll receive domain age and expiration data for international TLDs, which helps when signups, affiliates, or ad placements originate worldwide.
- Real-time classification: When you enrich a domain, the platform performs fresh analysis rather than relying on stale lookups—important when a domain has just been registered or renewed.
- Industry-level categories: The same response model maps content to IAB taxonomy when you need content policy checks in addition to domain age checks.
- Simple API integration: A straightforward REST flow with bearer auth and a JSON payload means your PHP, JavaScript, or data pipelines can integrate quickly.
- Superior compliance and filtering: Combine age gates, expiration thresholds, and IAB categories to enforce onboarding policies or brand-safety guidelines in a single enrichment step.
You can get started now with a 7-day trial; the Starter plan is $39.99/mo. Failed or unreachable calls are not billed. Create your account here: Register.
What you’ll build: a PHP check that returns domain age and expiration
We’ll wire up a single POST to the Domain Age API and parse these fields:
- domain_age_date: ISO date the domain was first registered.
- domain_age_days_ago: Number of days since registration.
- domain_expiration_date: ISO expiration date.
- domain_expiration_days_left: Days until expiration.
Typical uses:
- Account signup: If domain_age_days_ago < 30, require manual review.
- Partner vetting: Require domain_age_days_ago >= 365 and domain_expiration_days_left > 14.
- Ad placement auditing: Exclude domains expiring within 7 days to avoid delivery interruptions.
Endpoint and request format
Use a POST request with bearer auth and a JSON payload containing the URL you want to evaluate.
POST https://www.klazify.com/api/domain_expiration
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
cURL request you can copy
curl -X POST "https://www.klazify.com/api/domain_expiration" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://cbsnews.com"}'
Replace YOUR_API_KEY with your token. The url field can be a full URL or domain. Failed or unreachable calls are not billed.
Official sample response and the fields you’ll use
Below is an official example from the Klazify documentation that includes domain registration data inside the response. Your integration will rely on these exact fields (domain_age_date, domain_age_days_ago, domain_expiration_date, domain_expiration_days_left).
{
"domain": {
"categories": [
{
"confidence": 0.92,
"name": "/Computers & Electronics/Consumer Electronics",
"IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
},
{
"confidence": 0.89,
"name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
}
],
"social_media": null,
"logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
},
"success": true,
"objects": {
"company": {
"url": "https://www.apple.com/",
"name": "Apple",
"city": "Cupertino",
"stateCode": "CA",
"countryCode": "US",
"employeesRange": "100K+",
"revenue": 274515000000,
"raised": null,
"tags": [
"E-commerce",
"Consumer Electronics",
"Mobile",
"B2C"
],
"tech": [
"omniture_adobe_analytics",
"atlassian_confluence",
"successfactors",
"apache_apex",
"talend",
"oracle_peoplesoft",
"salesforce",
"stripe",
"dell_boomi_atomsphere",
"gigya",
"sage_50cloud",
"quickbooks",
"webmethods",
"apache_tomcat",
"alteryx",
"tibco_rendezvous",
"atlassian_jira",
"..."
]
}
},
"domain_registration_data": {
"domain_age_date": "1987-02-19",
"domain_age_days_ago": "13026",
"domain_expiration_date": "2030-02-20",
"domain_expiration_days_left": "123"
},
"similar_domains": [
"bestbuy.com",
"icloud.com",
"microsoft.com",
"macrumors.com",
"google.com",
"samsung.com",
"twitter.com",
"hp.com",
"bhphotovideo.com",
"dell.com"
]
}
How to use it:
- domain_registration_data.domain_age_date: use as a stable ISO date for reporting and audits.
- domain_registration_data.domain_age_days_ago: use directly in rules (e.g., age < 30 implies high risk).
- domain_registration_data.domain_expiration_date: useful for notifications and customer success workflows.
- domain_registration_data.domain_expiration_days_left: use to block or warn when a domain is close to expiry.
If you also call the categorization endpoint, you can combine IAB content categories with domain age data to fine-tune brand safety and onboarding rules. See the Documentation for more details.
PHP implementation: production-ready snippet
Drop this function into your PHP service to fetch and parse domain age fields. It uses cURL and returns a compact associative array you can store or score against.
<?php
function getDomainAgeData(string $apiKey, string $url): array {
$endpoint = "https://www.klazify.com/api/domain_expiration";
$payload = json_encode(["url" => $url]);
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer {$apiKey}",
"Content-Type: application/json",
"Content-Length: " . strlen($payload)
],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_TIMEOUT => 15
]);
$resp = curl_exec($ch);
if ($resp === false) {
$err = curl_error($ch);
curl_close($ch);
// Not billed for failed or unreachable calls
throw new RuntimeException("Klazify request failed: {$err}");
}
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$json = json_decode($resp, true);
if ($status < 200 || $status >= 300 || !isset($json["domain_registration_data"])) {
// Include raw response for debugging or alerting
throw new RuntimeException("Unexpected Klazify response ({$status}): " . substr($resp, 0, 500));
}
$reg = $json["domain_registration_data"];
return [
"age_date" => $reg["domain_age_date"] ?? null,
"age_days_ago" => isset($reg["domain_age_days_ago"]) ? (int)$reg["domain_age_days_ago"] : null,
"expiration_date" => $reg["domain_expiration_date"] ?? null,
"expiration_days_left" => isset($reg["domain_expiration_days_left"]) ? (int)$reg["domain_expiration_days_left"] : null
];
}
// Example usage:
try {
$result = getDomainAgeData("YOUR_API_KEY", "https://cbsnews.com");
// Gate signups: require domain older than 30 days and not expiring this week
$isTrusted = ($result["age_days_ago"] !== null && $result["age_days_ago"] >= 30)
&& ($result["expiration_days_left"] === null || $result["expiration_days_left"] > 7);
if (!$isTrusted) {
// Route to manual review, block, or add friction
}
// Cache $result by registrable domain
} catch (Throwable $e) {
// Log and degrade gracefully; failed calls are not billed
}
JavaScript example (Node.js) for pipelines and workers
If your ingestion pipeline or queue workers run on Node.js, use this fetch call. It reads the same fields and applies a simple rule.
import fetch from "node-fetch";
async function fetchDomainAge(url) {
const resp = await fetch("https://www.klazify.com/api/domain_expiration", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({ url })
});
if (!resp.ok) {
const text = await resp.text();
throw new Error(`Klazify error ${resp.status}: ${text.slice(0, 500)}`);
}
const data = await resp.json();
const reg = data.domain_registration_data || {};
return {
ageDate: reg.domain_age_date || null,
ageDaysAgo: reg.domain_age_days_ago ? Number(reg.domain_age_days_ago) : null,
expirationDate: reg.domain_expiration_date || null,
expirationDaysLeft: reg.domain_expiration_days_left ? Number(reg.domain_expiration_days_left) : null
};
}
(async () => {
const age = await fetchDomainAge("https://cbsnews.com");
// Example policy: warn if expirationDaysLeft is under 14
if (age.expirationDaysLeft !== null && age.expirationDaysLeft <= 14) {
console.warn("Domain expires soon:", age);
}
})();
How to use the returned fields in your workflow
- Risk scoring: Subtract points when domain_age_days_ago is small (e.g., 0–30) to flag fresh domains often used in fraud.
- Compliance gates: Enforce minimum age thresholds for partners (e.g., 365+ days).
- Lifecycle operations: Create renewal reminders when domain_expiration_days_left is under your threshold (e.g., 30 or 14 days).
- Brand safety: Combine age checks with IAB category mapping from the categorization endpoint to route domains through the correct policy path.
Caching, batching, and operational details
Latency and cost improve dramatically with a few operational patterns.
- Caching per registrable domain: Cache the four fields (age date, age days ago, expiration date, expiration days left) keyed by the registrable domain (e.g., example.co.uk). Refresh daily or when cache is older than 24 hours. Expiration_days_left changes daily but rarely needs minute-level freshness for policy gates.
- Handling unknown or new domains: If a domain is too new or has incomplete data, treat domain_age_days_ago as 0 or null and route to manual review. Log these cases for recheck later.
- High-level batching: If you process large queues, parallelize requests with concurrency limits. Respect HTTP 429 or backoff guidance if present. Consolidate repeated domains within a job run and query them once.
- Error handling: On non-2xx status or network failure, do not hard-block mission-critical flows. Use defaults, queue a retry, and note that failed or unreachable calls are not billed.
- Versioning and fields: Consume only the documented fields shown here; avoid strict schema assumptions beyond domain_registration_data to keep your integration resilient.
Mapping domain age and categories to your taxonomy
Many teams combine registration data with IAB-based content categories from Klazify’s categorization endpoint. Suggested approach:
- Define internal risk levels based on domain_age_days_ago (e.g., New: 0–30, Young: 31–180, Mature: 181–365, Established: 366+).
- Define policy matrices by risk level and IAB category (e.g., certain categories require Established status to be approved).
- Store both the raw values and your mapped labels. That way dashboards can show precise numbers and policy labels.
For category and company enrichment fields, see the Documentation. If you run multiple services across regions or vendors, the MCP can help centralize controls.
Comparing the domain age and expiration fields
| Field | Type | Meaning | Common Uses | Storage Tip |
|---|---|---|---|---|
| domain_age_date | ISO date (YYYY-MM-DD) | First registration date | Audit reports, timeline charts | Store as date; no time zone ambiguity |
| domain_age_days_ago | Integer (days) | Age since registration | Risk scoring, gating | Cache and update daily |
| domain_expiration_date | ISO date (YYYY-MM-DD) | Next renewal date | Reminders, compliance checks | Store as date; display in org’s locale |
| domain_expiration_days_left | Integer (days) | Time until expiration | Proactive renewal nudges | Recompute or refresh daily |
End-to-end flow recommendations
1) Normalize input
Extract the registrable domain (e.g., example.com from sub.example.com) before calling the API. Pass a canonical URL or domain string in the url parameter.
2) Check cache and deduplicate
Look up cached results by registrable domain. Deduplicate domains within the same batch to avoid redundant calls.
3) Call the API with predictable timeouts
Use timeouts of 10–15 seconds and retries with jitter. Treat non-2xx as soft failures and fall back to defaults when your workflow must continue.
4) Persist raw and derived values
Store the returned four fields and the retrieval timestamp. Also store your derived labels (e.g., Established) for BI queries.
5) Monitor and alert
Track error rates, timeouts, and response sizes. Alert on unusual spikes in young domains or many soon-to-expire partners.
Testing and validation checklist
- Unit tests assert that parsing handles missing fields gracefully (nulls allowed).
- Load tests ensure your concurrency and caching prevent throttling.
- Canary jobs verify TTL-based refreshes update expiration_days_left daily.
- Security: Scope and rotate your API key; never log it.
Next steps
- Add categorization via the main endpoint if you need IAB taxonomy with your age-based checks: https://www.klazify.com/api/categorize.
- Wire alerts when domain_expiration_days_left is under a threshold that matters to your operations (e.g., 14 days).
- Gate signups or ad placements until a domain meets your minimum age policy.
Set up your account to begin testing: Register. Explore parameter and response references in the Documentation.
FAQ
-
Does the API require a full URL or just a domain?
Send either. For consistency, normalize to the registrable domain before request and caching.
-
How often should I refresh domain_expiration_days_left?
Refresh daily for operational checks. Increase frequency only if a workflow needs near real-time updates.
-
What happens if the target domain is unreachable?
The request may fail; failed or unreachable calls are not billed. Use retries and fallbacks, and try again later.
-
Can I combine domain age with IAB categories?
Yes. Use the categorization endpoint to get IAB-mapped categories and apply both age- and content-based policies.
-
How do I start and what does it cost?
Starter is $39.99/mo with a 7-day trial. Create a free account here: Register.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free