Image Alt

Code Examples

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

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Let’s start with the most basic PHP example. We will check if the domain name “whoapi.com” is available for registration. If there’s an error it will be shown automatically; if not, you should see “1” (domain taken) as a resulting string.

<?
// prepare vars
$domain    = "whoapi.com";     // domain to check
$r         = "taken";             // request type: domain availability
$apikey    = "demokey";        // your API key

// API call
$output = json_decode(file_get_contents(
    "http://api.whoapi.com/?domain=$domain&r=$r&apikey=$apikey"), true);
if($output['status'] == 0){
    // show the result
    echo $output['taken'];
    }else{
    // show error
    echo $output['status_desc'];
}
?>

Same example using CURL. This is the recommended method due to CURL Timeout option with better connection error handling.
At the moment, JSON is the only output format we support.

<?
// prepare vars
$domain    = "whoapi.com";     // domain to check
$r         = "taken";             // request type: domain availability
$apikey    = "demokey";        // your API key

// API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
        "http://api.whoapi.com/?domain=$domain&r=$r&apikey=$apikey");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
$output  = json_decode(curl_exec($ch), true);
curl_close($ch);
if($output['status'] == 0){
    // show the result
    echo $output['taken'];
    }else{
    // show error
    echo $output['status_desc'];
}
?>

Javascript

We’re going to use our Domain Availability API to check if the domain name “whoapi.com” is available for registration. If there’s an error it will be translated automatically, if not you should see “1” (domain taken) as a resulting string.

<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
	var domain 	= "whoapi.com";	// domain name you want to check
	var r 		= "taken";	// check availability
	var apikey 	= "demokey";	// your API key

	// API call
	$.getJSON('http://api.whoapi.com/?domain='+domain+'&r='+r+'&apikey='+apikey,
	function(dataObj){
		if(dataObj.status == 0){
			// show the result
			$('#result').html(dataObj.data);
			}else{
			// show error
			$('#result').html(dataObj.status_desc);
		}
	});
</script>
<div id="result">[please wait]</div>

Ruby

We’re going to check if the domain name “whoapi.com” is available for registration. If there’s an error it will be translated automatically, if not you should see “1” (domain taken) as a resulting string.

require 'open-uri'
require 'json'

domain 	= "whoapi.com"   # domain to check
r  	= "taken"        # request type: domain availability
apikey 	= "demokey"      # your API key

output = JSON.parse(open(
"http://api.whoapi.com/?domain=#{domain}&r=#{r}&apikey=#{apikey}").read)

if output["status"].to_i == 0
 puts output["taken"]
else
 puts output["status_desc"]
end

Python

We’re going to use our API to check if the domain name “whoapi.com” is available for registration. If there’s an error it will be translated automatically, if not you should see “1” (domain taken) as a resulting string. This code is the courtesy of Good Code.

#!/usr/bin/env python

import requests

def whoapi_check_domain_taken(domain, apikey):

    r = requests.get('http://api.whoapi.com', dict(
        domain=domain,
        r='taken',
        apikey=apikey))

    if r.status_code == 200:
        data = r.json()
        if int(data['status']) == 0:
            return int(data['taken']) == 1
        else:
            raise Exception(data['status_desc'])
    else:
        raise Exception('unexpected status code %d' % r.status_code)

print whoapi_check_domain_taken('whoapi.com', 'demokey')

Objective C

We’re going to use our API to check if the domain name “whoapi.com” is available for registration. If there’s an error it will be translated automatically, if not you should see “1” (domain taken) as a resulting string. This code is the courtesy of Good Code.

NSString *domain   = @"whoapi.com";     // domain to check
    NSString *r        = @"taken";             // request type: domain availability
    NSString *apikey   = @"demokey";        // your API key

    // API call

    NSString *urlAsString = [NSString stringWithFormat:@
    "http://api.whoapi.com/?domain=%@&r=%@&apikey=%@", domain, r, apikey];

    NSURL *url = [[NSURL alloc] initWithString:urlAsString];
    NSLog(@"%@", urlAsString);

    [NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:url]
    queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response,
    NSData *data, NSError *error) {


        if (error) {

        } else {
            NSDictionary *json=[NSJSONSerialization JSONObjectWithData:data options:
            NSJSONReadingMutableContainers error:nil];
            NSArray * serverData=[[NSArray alloc]init];
            serverData=[json valueForKeyPath:@"status"];

            if(serverData == 0){
                // show the result
                serverData=[json valueForKeyPath:@"taken"];
                NSLog(@"%@", serverData);
            }else{
                // show error
                serverData=[json valueForKeyPath:@"status_desc"];
                NSLog(@"%@", serverData);

            }

        }
    }];

C#(.NET)

We’re going to use our API to check if the domain name “whoapi.com” is available for registration. If there’s an error it will be translated automatically, if not you should see “1” (domain taken) as a resulting string.

using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
using System.Web;

namespace WhoAPICodeExample
{
    public class WhoAPIWrapper
    {
        public string CheckDomainTaken(string domain, string apiKey)
        {
            // Creating WebRequest.
            WebRequest request = WebRequest.Create(String.Format("http://api.whoapi.com/?domain={0}&r={1}&apikey={2}", domain, "taken", apiKey));

            // Getting response from server.
            WebResponse response = request.GetResponse();

            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(response.GetResponseStream());

            // Read the content.
            string responseFromServer = reader.ReadToEnd();

            // Parsing response from server to JSON Object.
            JObject output = JObject.Parse(responseFromServer);

            if (output.Value<int>("status") == 0)
                // Show the result
                return output.Value<string>("taken");
            else
                // Show error
                return String.Format("Unexpected status code: {0}. ", output["status_desc"]);
        }
    }
}

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!

PHP

Coming Soon!

Javascript

Coming Soon!

Ruby

Coming Soon!

Python

Coming Soon!

Objective C

Coming Soon!

C#(.NET)

Coming Soon!