View our
Domain Age API Code Examples
Please read the API documentation before you start using our APIs in production.
The API key used in these examples is for demonstrative purposes and can be used only to check whoapi.com
PHP Code Example
Basic PHP example using cURL. We will get domain age for the domain name “whoapi.com”.
<?php
$apiKey = "demokey";
$domain = "whoapi.com";
$url = "http://api.whoapi.com/?domain=" . urlencode($domain) . "&r=domainage&apikey=" . $apiKey;
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
die("cURL error: " . curl_error($ch));
}
curl_close($ch);
// Decode JSON response
$data = json_decode($response, true);
// Handle API response
if ($data["status"] === 0) {
echo "Domain: " . $data["domain_name"] . "<br>";
echo "Registered: " . ($data["registered"] ? "Yes" : "No") . "<br>";
echo "Created: " . $data["date_created"] . "<br>";
echo "Expires: " . $data["date_expires"] . "<br>";
echo "Updated: " . $data["date_updated"] . "<br>";
echo "Age (days): " . $data["age_in_days"] . "<br>";
echo "Age (years): " . $data["age_in_years"] . "<br>";
echo "Requests remaining: " . $data["_requests_available"] . "<br>";
} else {
echo "API Error: " . $data["status_desc"];
}
?>
Javascript Code Example
We will get a domain age for the domain name “whoapi.com”.
const url = "http://api.whoapi.com/?domain=whoapi.com&r=domainage&apikey=demokey";
fetch(url)
.then(response => response.json())
.then(data => {
if (data.status === 0) {
console.log("Domain:", data.domain_name);
console.log("Registered:", data.registered);
console.log("Created:", data.date_created);
console.log("Expires:", data.date_expires);
console.log("Age (days):", data.age_in_days);
console.log("Age (years):", data.age_in_years);
console.log("Requests remaining:", data._requests_available);
} else {
console.error("API Error:", data.status_desc);
}
})
.catch(error => console.error("Request failed:", error));
Ruby Code Example
We will get domain age for the domain name “whoapi.com”.
require 'net/http'
require 'json'
require 'uri'
url = URI("http://api.whoapi.com/?domain=whoapi.com&r=domainage&apikey=demokey")
response = Net::HTTP.get(url)
data = JSON.parse(response)
if data["status"] == 0
puts "Domain: #{data["domain_name"]}"
puts "Registered: #{data["registered"]}"
puts "Created: #{data["date_created"]}"
puts "Expires: #{data["date_expires"]}"
puts "Updated: #{data["date_updated"]}"
puts "Age (days): #{data["age_in_days"]}"
puts "Age (years): #{data["age_in_years"]}"
puts "Requests remaining: #{data["_requests_available"]}"
else
puts "API Error: #{data["status_desc"]}"
end
Python Code Example
We will get domain age for the domain name “whoapi.com”. Naturally, don’t forget to add your API key.
import requests
url = "http://api.whoapi.com/"
params = {
"domain": "whoapi.com",
"r": "domainage",
"apikey": "demokey"
}
response = requests.get(url, params=params)
data = response.json()
if data["status"] == 0:
print("Domain:", data["domain_name"])
print("Registered:", data["registered"])
print("Created:", data["date_created"])
print("Expires:", data["date_expires"])
print("Updated:", data["date_updated"])
print("Age (days):", data["age_in_days"])
print("Age (years):", data["age_in_years"])
print("Requests remaining:", data["_requests_available"])
else:
print("API Error:", data["status_desc"])
Objective C Code Example
We will get a domain age for the domain name “whoapi.com”. Reminder, you have to add your API key.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *urlString = @"http://api.whoapi.com/?domain=whoapi.com&r=domainage&apikey=demokey";
NSURL *url = [NSURL URLWithString:urlString];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Request failed: %@", error.localizedDescription);
return;
}
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (jsonError) {
NSLog(@"JSON parse error: %@", jsonError.localizedDescription);
return;
}
if ([json[@"status"] intValue] == 0) {
NSLog(@"Domain: %@", json[@"domain_name"]);
NSLog(@"Registered: %@", json[@"registered"]);
NSLog(@"Created: %@", json[@"date_created"]);
NSLog(@"Expires: %@", json[@"date_expires"]);
NSLog(@"Updated: %@", json[@"date_updated"]);
NSLog(@"Age (days): %@", json[@"age_in_days"]);
NSLog(@"Age (years): %@", json[@"age_in_years"]);
NSLog(@"Requests remaining: %@", json[@"_requests_available"]);
} else {
NSLog(@"API Error: %@", json[@"status_desc"]);
}
}];
[task resume];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
C#(.NET) Code Example using HttpClient
We will get domain age for the domain name “whoapi.com”.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
class Program
{
static async Task Main()
{
string url = "http://api.whoapi.com/?domain=whoapi.com&r=domainage&apikey=demokey";
using (HttpClient client = new HttpClient())
{
try
{
string response = await client.GetStringAsync(url);
JObject data = JObject.Parse(response);
if ((int)data["status"] == 0)
{
Console.WriteLine("Domain: " + data["domain_name"]);
Console.WriteLine("Registered: " + data["registered"]);
Console.WriteLine("Created: " + data["date_created"]);
Console.WriteLine("Expires: " + data["date_expires"]);
Console.WriteLine("Updated: " + data["date_updated"]);
Console.WriteLine("Age (days): " + data["age_in_days"]);
Console.WriteLine("Age (years): " + data["age_in_years"]);
Console.WriteLine("Requests remaining: " + data["_requests_available"]);
}
else
{
Console.WriteLine("API Error: " + data["status_desc"]);
}
}
catch (Exception ex)
{
Console.WriteLine("Request failed: " + ex.Message);
}
}
}
}
Java Code Example
We will get the domain age for the domain name “whoapi.com”. Instead of demokey you need to type your API key.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;
public class WhoAPIExample {
public static void main(String[] args) {
try {
String urlString = "http://api.whoapi.com/?domain=whoapi.com&r=domainage&apikey=demokey";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream())
);
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
JSONObject data = new JSONObject(response.toString());
if (data.getInt("status") == 0) {
System.out.println("Domain: " + data.getString("domain_name"));
System.out.println("Created: " + data.getString("date_created"));
System.out.println("Expires: " + data.getString("date_expires"));
System.out.println("Age (days): " + data.getInt("age_in_days"));
System.out.println("Age (years): " + data.getDouble("age_in_years"));
System.out.println("Requests remaining: " + data.getInt("_requests_available"));
} else {
System.out.println("API Error: " + data.getString("status_desc"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Summary
The provided code examples demonstrate how to make API requests to the WhoAPI service to retrieve the age and domain registration dates of a specified domain using different programming languages. The examples use various HTTP client libraries (such as cURL, fetch, requests, HttpClient, Net::HTTP, etc.) to send HTTP GET requests to the WhoAPI Domain Age API endpoint.
It’s important to review the API documentation provided by WhoAPI to understand the available request types, response formats, and any specific requirements or limitations of the API.
Please note that the provided code snippets assume the availability of the WhoAPI service and may require modifications to the API endpoint or authentication mechanism if there are any changes to the service. It’s also important to use a valid API key provided by WhoAPI to authenticate the requests properly.