Brand Alert API
Bulk Whois API
DNS Lookup API
Domain Availability API
Email Verification API
Registrant Alert API
Reverse Whois API
Whois API

Making a query to Bulk Whois API web service

Here you’ll find short examples of using www.whoisxmlapi.com Hosted Bulk Whois Web API implemented in multiple languages.

You can view more sample code, incl. dealing with the API’s response formats, requests order and more, in the repository.

Please, refer to Bulk Whois API User Guide for request and response formats, usage limits.

using Hs = System.Collections.Hashtable; using System.Threading;
using Js = System.Web.Script.Serialization.JavaScriptSerializer;

internal static class BulkWhoisApiSample {
    const string Url = "https://whoisxmlapi.com/BulkWhoisLookup/bulkServices";
    const string ApiKey="Bulk Whois API Key", Id="requestId";
    static readonly string[] Dom = {"whoisxmlapi.com", "google.com"};
    //
    private static void Main() {
        var r = Api("/bulkWhois", new Hs{{"domains", Dom}});
        if (r["messageCode"] != 200) throw new System.Exception(r["message"]);
        var p = new Hs{{"startIndex",1},{"maxRecords",Dom.Length},{Id,r[Id]}};
        while (Api("/getRecords", p)["recordsLeft"] > 0) Thread.Sleep(3000);
        System.Console.Write(new Js().Serialize(Api("/getRecords", p)));
    }//
    private static dynamic Api(string path, Hs data, string fm="json") {
        data["apiKey"]=ApiKey; data["outputFormat"]=fm;
        var req = System.Net.WebRequest.Create(Url + path); req.Method="POST";
        var arg =System.Text.Encoding.UTF8.GetBytes(new Js().Serialize(data));
        req.GetRequestStream().Write(arg, 0, arg.Length);
        return new Js().Deserialize<dynamic>(new System.IO.StreamReader(
            req.GetResponse().GetResponseStream()).ReadToEnd());
    }
}

import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.*;
import org.json.JSONObject;

public class BulkWhoisApiSample {
    static String url = "https://whoisxmlapi.com/BulkWhoisLookup/bulkServices";
    static String apiKey = "Bulk Whois API Key", fmt = "json";
    static String[] dom = {
        "threatintelligenceplatform.com",
        "google.com"
    };

    public static void main(String[] args) throws Exception {
        JSONObject arg = new JSONObject().put("maxRecords", dom.length);
        int err;
        JSONObject r = api("/bulkWhois", new JSONObject().put("domains", dom));
        if ((err = r.getInt("messageCode")) != 200) throw new Exception("" + err);
        arg.put("requestId", r.getString("requestId")).put("startIndex", 1);
        while (api("/getRecords", arg).getInt("recordsLeft") > 0)
            Thread.sleep(3000);
        System.out.println(api("/getRecords", arg).toString(2));
    }
    private static JSONObject api(String uri, JSONObject arg) throws Exception {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost rq = new HttpPost(url + uri);
        arg.put("apiKey", apiKey).put("outputFormat", fmt);
        rq.setEntity(new org.apache.http.entity.StringEntity(arg.toString()));
        String r = client.execute(rq, new BasicResponseHandler());
        client.close();
        return new JSONObject(r);
    }
}

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    const url = "https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices", m = 3000;
    let apiKey = "Bulk Whois API Key", x = $.extend, s = JSON.stringify, f = "json", t;

    function api(uri, data, cb) {
        let b = {apiKey: apiKey, outputFormat: f}, p = "post", a = $.ajax;
        a({data: s(x(b, data)), type: p, url: url + uri, complete: d => cb(d.responseJSON)});
    }

    api("/bulkWhois", {domains: ["threatintelligenceplatform.com"]}, r =>
        t = setInterval((i, e, u) => api(u, x({}, i, {startIndex: 2, maxRecords: 0}), r =>
            !r.recordsLeft && !clearInterval(t) && api(u, i, r => $(e).append(s(r)))), m,
            {requestId: r.requestId, startIndex: 1, maxRecords: 1}, "body", "/getRecords"));
</script>

var fs = require('fs'), https = require('https');

var dom = ['google.com', 'youtube.com', 'facebook.com', 'whoisxmlapi.com'];
var srv = 'www.whoisxmlapi.com', url = '/BulkWhoisLookup/bulkServices/';
var apiKey = 'Your Bulk Whois API Key', file = 'bulk.csv';

function api(path, data, callback) {
    var baseData = {apiKey: apiKey, outputFormat: 'json'};
    var header = {'Content-Type': 'application/json'}, body = '';
    var opts = {host: srv, path: url + path, method: 'POST', headers: header};
    https.request(opts, function (response) {
        response.on('data', function (chunk) {
            body += chunk;
        });
        response.on('end', function () {
            callback(body);
        });
    }).end(JSON.stringify(Object.assign({}, baseData, data)));
}

// This will save whois record info for all domains as 'bulk.csv' in curr. dir
api('bulkWhois', {domains: dom}, function (body) {
    var id = {requestId: JSON.parse(body).requestId, startIndex: dom.length + 1};
    var timer = setInterval(function () {
        api('getRecords', Object.assign({}, id, {maxRecords: 0}), function (body) {
            if (JSON.parse(body).recordsLeft) {
                return;
            }
            clearInterval(timer);
            if (typeof JSON.parse(body).recordsLeft === 'undefined') {
                return;
            }
            api('download', id, function (csv) {
                fs.writeFile(file, csv);
            });
        });
    }, 3000);
});

#!/usr/bin/perl
use Package::Alias
  http => 'HTTP::Request',
  ua   => 'LWP::UserAgent',
  js   => 'JSON';

my $url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices';
my ( $apiKey, $dom, $fm ) =
  ( 'Bulk Whois API Key', ['google.com'], 'json' );
#
sub post_data {
    my ( $uri, $dt, $bs ) =
      ( @_, { apiKey => $apiKey, outputFormat => $fm } );
    my ( $ua, $req ) = ( ua->new(), http->new( 'POST', $url . $uri ) );
    $req->content( encode_json( { %$bs, %$dt } ) );
    return js->new->decode( $ua->request($req)->content );
}    #
my ( $res, $i ) =
  ( post_data( '/bulkWhois', { domains => $dom } ), 'requestId' );
$res->{messageCode}
  && ( $res->{messageCode} != 200 )
  && die $res->{messageCode};
my $arg = { $i => $res->{$i}, startIndex => @$dom + 1, maxRecords => 0 };
while ( post_data( '/getRecords', $arg )->{recordsLeft} > 0 ) { sleep(3); }
( $arg->{startIndex}, $arg->{maxRecords} ) = ( 1, @$dom + 0 );
print js->new->pretty->encode( post_data( '/getRecords', $arg ) );

<?php

$domains = ['google.com', 'youtube.com', 'facebook.com', 'whoisxmlapi.com'];
list($apiKey) = array('Your Bulk Whois API Key');
$url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices';

function api($path, array $data, $raw = false)
{
    global $url, $apiKey;
    $header = "Content-Type: application/json\r\nAccept: application/json\r\n";
    $params = compact('apiKey') + array('outputFormat' => 'json');
    $opts = array('http' => array('method' => 'POST', 'header' => $header));
    $opts['http']['content'] = json_encode($params + $data);
    $res = file_get_contents($url . $path, false, stream_context_create($opts));
    return $raw ? $res : json_decode($res);
}

$id = api('/bulkWhois', compact('domains'))->requestId;
$params = array('requestId' => $id, 'startIndex' => 5);
while (api('/getRecords', $params + array('maxRecords' => 0))->recordsLeft)
    sleep(5);
print(api('/download', $params, true));

$url, $out = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices','json'
$apiKey, $dom = 'Bulk Whois API Key', @('whoisxmlapi.com')

function Api ($U, $Data) {
    $b=@{apiKey=$apiKey;outputFormat=$out}+$Data|ConvertTo-Json
    $r=Invoke-WebRequest -Uri ($url+$U) -Method POST -Body $b|ConvertFrom-Json
    if ($r.messageCode -and $r.messageCode -ne 200){throw "$($r.messageCode)"}
    return $r
}
$id, $c = @{requestId=(Api '/bulkWhois' @{domains=$dom}).requestId},$dom.Count
Do {
    $num=(Api '/getRecords' ($id+@{startIndex=$c+1;maxRecords=0})).recordsLeft
    Start-Sleep -s 5
} Until ($num -eq 0)

echo (Api '/getRecords' ($id + @{startIndex=1; maxRecords=$c})).whoisRecords

#!/usr/bin/env python3

try:
    from urllib.request import Request, urlopen
except ImportError:
    from urllib2 import Request, urlopen
from json import dumps, loads
from time import sleep

# Your API key
apiKey = 'Your API key'

#Input: list of domains to be queried
domains = ['whoisxmlapi.com', 'threatintelligenceplatform.com']

# Base URL of the API
url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices/'
# Encoding of python strings. Should be the default 'utf-8' also for punicode domain names
enc = 'utf-8'
# Interval in seconds between two checks of whether the results are ready
interval = 5

#Making the requests with the domain names, getting the request ID
payload_data = {'domains': domains, 'apiKey': apiKey, 'outputFormat': 'JSON'}
request = Request(url + 'bulkWhois')
request_id = loads(urlopen(request, dumps(payload_data).encode(enc)).read())['requestId']

#Set the payload for the next phase
payload_data.update({'requestId':request_id, 'searchType':'all', 'maxRecords':1, 'startIndex':1})
del payload_data['domains']

n_domains = len(domains)
n_remaining = n_domains
request = Request(url + 'getRecords')

while n_remaining > 0:
    print("Waiting %d seconds"%interval)
    sleep(interval)
    response = loads(urlopen(request, dumps(payload_data).encode(enc)).read())
    n_remaining = response['recordsLeft']
    print("%d of %d domains to be processed"%(n_remaining, n_domains))
print("Done, downloading data")
#Get the data
payload_data.update({'maxRecords': n_domains})
result = loads(urlopen(request, dumps(payload_data).encode(enc)).read().decode(enc, 'ignore'))
print(result)

require 'json'
require 'net/https'
require 'uri'

csv_filename, domains = 'whois_records.csv', %w[google.com whoisxmlapi.com]

def api(path, data)
  url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices'
  b ={ apiKey:'Bulk Whois API Key', outputFormat:'json' }
  uri = URI.parse(url + path)
  http, http.use_ssl = Net::HTTP.new(uri.host, uri.port), true
  req, req.body = Net::HTTP::Post.new(uri.request_uri), b.merge(data).to_json
  http.request(req).body
end
# This will save whois record info for all domains as #{csv_filename}
id = JSON.parse(api('/bulkWhois', domains: domains))['requestId']
data = { requestId: id, startIndex: domains.count + 1, maxRecords: 0 }
loop do
  break if JSON.parse(api('/getRecords', data))['recordsLeft'].zero?
  sleep 3
end
File.write(csv_filename, api('/download', requestId: id, startIndex: 1))