Integrate the Domain Expiration API in Python
A signup or vendor record can include a domain that is approaching expiration, but a domain name alone does not tell your pipeline when to review it. This guide shows you how to request registration dates with Klazify, read the expiration fields in Python, and route results into a review workflow without treating a missing date as a clean result.
Why use domain expiration data with website classification?
Klazify gives teams a way to add registration data and website context to a domain enrichment workflow. Expiration data helps answer when a domain may need attention; website categorization helps answer what kind of content the site contains. These are separate signals, and neither should be used as a substitute for the other.
For example, a CRM team can flag a signup domain for review when its expiration date is near. An ad operations team can audit a placement using content categories and separately note its registration status. A security team can add expiration data to an investigation, but an approaching expiration date alone does not establish that a site is malicious.
Klazify supports content analysis and IAB taxonomy mapping alongside domain registration data. For this integration, the relevant endpoint is https://www.klazify.com/api/domain_expiration. It accepts a URL in a JSON request and returns data you can use to assess domain age and expiration.
Before deploying the integration, create a free account through Register. The Starter plan is $39.99 per month with a 7-day trial; failed or unreachable calls are not billed. Review the Documentation for current integration details and account limits.
Send an expiration request
Send a POST request with a Bearer token and a JSON body containing the url to inspect. Replace YOUR_API_KEY with your API key:
curl --request POST 'https://www.klazify.com/api/domain_expiration' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{"url":"https://cbsnews.com"}'
The request identifies the website with a URL; the expiration information concerns the domain registration. Keep the API key on the server or in a secret manager rather than embedding it in a browser application or committing it to source control.
In a production pipeline, retain the input domain with the result so that you can attach the registration data to the right signup, vendor, or placement record. If multiple records use the same domain, reuse a sufficiently fresh cached result rather than making a separate request for every record.
Understand the response fields
The following documented example is a broader Klazify response. It illustrates the registration fields alongside classification and company data; it is not shown as the response to the preceding expiration request.
{
"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"
]
}
For an expiration workflow, focus on the four values under domain_registration_data in this example. The day counts are represented as strings, so parse them before numeric comparisons and handle missing or nonnumeric values explicitly.
| Field | Meaning | Practical use |
|---|---|---|
domain_age_date |
A date associated with domain age | Retain as registration context for a review. |
domain_age_days_ago |
Domain age expressed as a number of days | Use as a relative age signal after parsing it as an integer. |
domain_expiration_date |
The reported expiration date | Store the date and compare it with your review schedule. |
domain_expiration_days_left |
Days remaining until the reported expiration | Compare with a threshold set by your organization. |
The dates are date-only values, not timestamps with a timezone. Decide which timezone your application uses when converting an expiration date into a reminder, and document that decision for downstream teams. Day counts are relative values: cache them with an observation time and refresh them rather than treating them as permanently current.
The sample also shows domain.categories, category name and confidence, an IAB mapping, and a top-level success value. These illustrate a broader enrichment response, not evidence that every expiration request returns category data. If your application also needs content classification, use the separately documented categorization capability and map its results to your own policy taxonomy.
Call the endpoint from Python
This example uses Python’s standard library, reads the key from an environment variable, and takes the URL to inspect as a command-line argument. It accepts registration fields either inside domain_registration_data, as in the broader example above, or at the response’s top level. It reports an error if neither location contains the expected fields, so an unexpected response does not silently become an expired or safe result.
import json
import os
import sys
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
ENDPOINT = "https://www.klazify.com/api/domain_expiration"
FIELDS = (
"domain_age_date",
"domain_age_days_ago",
"domain_expiration_date",
"domain_expiration_days_left",
)
def integer_or_none(value):
if value is None:
return None
try:
return int(value)
except (TypeError, ValueError):
return None
def get_registration_data(api_key, url):
body = json.dumps({"url": url}).encode("utf-8")
request = Request(
ENDPOINT,
data=body,
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
method="POST",
)
with urlopen(request) as response:
payload = json.load(response)
if not isinstance(payload, dict) or payload.get("success") is False:
raise ValueError("The API did not return a usable response.")
registration = payload.get("domain_registration_data", payload)
if not isinstance(registration, dict):
raise ValueError("Registration data is not an object.")
if not any(field in registration for field in FIELDS):
raise ValueError("Expected registration fields were not returned.")
return {
"domain_age_date": registration.get("domain_age_date"),
"domain_age_days_ago": integer_or_none(
registration.get("domain_age_days_ago")
),
"domain_expiration_date": registration.get("domain_expiration_date"),
"domain_expiration_days_left": integer_or_none(
registration.get("domain_expiration_days_left")
),
}
def main():
api_key = os.environ.get("KLAZIFY_API_KEY")
if not api_key or len(sys.argv) != 2:
sys.exit("Set KLAZIFY_API_KEY and pass one URL as an argument.")
try:
data = get_registration_data(api_key, sys.argv[1])
except (HTTPError, URLError, ValueError, OSError) as error:
sys.exit(f"Could not retrieve registration data: {error}")
print(json.dumps(data, indent=2))
days_left = data["domain_expiration_days_left"]
if days_left is None:
print("Expiration day count unavailable; route for review.")
else:
print("Compare the day count with your configured review threshold.")
if __name__ == "__main__":
main()
Set KLAZIFY_API_KEY in your environment, save the script, and run it with the URL you want to inspect as its argument. The result preserves the date strings and converts the two day counts to integers where possible. A missing or unparseable count becomes None, which the example routes to review rather than comparing against a threshold.
Connect the final comparison to a threshold owned by your application. For example, if the returned days remaining are at or below your configured threshold, create a review task or mark the CRM record for attention. Keep the raw response or an audit record where appropriate, and verify the current response shape and error behavior in the documentation before making the result a blocking decision.
Operate the integration at scale
Normalize and cache by domain. Extract and consistently normalize the hostname from each input before using it as a cache key. Store the reported expiration date, relative day count, and the time you retrieved them; refresh according to how quickly your workflow needs to notice registration changes. Be careful with hostnames and subdomains: define which domain your records refer to instead of assuming every hostname has a separate registration.
Queue work and respect rate limits. For a large CRM import or placement audit, deduplicate domains first, then process requests through a queue with controlled concurrency. Check the limits for your account in the documentation, and use backoff for temporary failures or rate-limit responses. The request above describes one URL per call; do not assume the endpoint accepts a batch payload.
Separate unknown from expired. New domains, unavailable registration data, malformed inputs, and unreachable calls need their own status. A missing expiration date is not proof that a domain has expired, and a future date is not proof that its content is safe. Preserve the reason for review so an operator can distinguish a data gap from a date-based alert.
Keep category policy independent. If you also classify websites, map returned category names or IAB values to your internal labels in a maintained lookup. Decide what to do with categories that have no mapping or with low-confidence results, and audit changes to the mapping. Expiration status should be a separate field: it can inform a review without silently changing a category-based block or allow decision.
Monitor freshness and failures. Track request failures, missing registration fields, cache age, and the number of records sent for manual review. Configure request timeouts and a retry policy suitable for your pipeline, and avoid retrying indefinitely when an input or credential needs correction. For teams integrating Klazify into tool-driven workflows, see MCP for another integration option.
FAQ
Does a near-expiration domain need to be blocked?
Not necessarily. Use expiration as a review signal alongside your own policy and other evidence. A registration date alone does not establish whether a website is unsafe.
Should I use the expiration date or days remaining?
Store the date for durable context and use the day count for a convenient relative comparison. Because the count changes over time, record when it was retrieved and refresh it before making time-sensitive decisions.
What should happen when registration data is missing?
Mark the result as unknown and send it to a retry or review path. Do not convert a missing value to zero or interpret it as a confirmed expiration.
Can I classify content with the expiration endpoint?
The expiration workflow is for registration data. Klazify also provides website categorization, but treat category results as a separate signal and check the documentation for the appropriate request and response.
Start with a free Klazify account, run the request against a domain you manage, and connect the returned dates to a review queue before introducing automated enforcement.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free