API Usage Examples

Command line example to query if “127.0.0.2” is listed in AuthBL:

curl -k -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" https://apibl.spamhaus.net/lookup/v1/AUTHBL/127.0.0.2
{
   "resp":[
       1020
   ],
   "status": 200
}

Same example with an HTML media type:

curl -k -H "Authorization: Bearer <TOKEN>" -H "Accept: text/html" https://apibl.spamhaus.net/lookup/v1/AUTHBL/127.0.0.2

<html>
<head>
 <title></title>
</head>
<body>
   1020
</body>
</html>

Command line example to query if the domain “test” is listed in DBL:

curl -k -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" https://apibl.spamhaus.net/lookup/v1/DBL/test
{
   "resp":[
       2002
   ],
   "status": 200
}

Command line example with an error and a JSON media type:

curl -k -H "Authorization: Bearer <TOKEN>" -H "Accept: application/json" //apibl.spamhaus.net/lookup/v1/DBL/i.dont.exist
{
   "status": 404
}

Command line example with an error and an HTML media type:

curl -k -H "Authorization: Bearer <TOKEN>" -H "Accept: text/html" //apibl.spamhaus.net/lookup/v1/DBL/i.dont.exist

<!DOCTYPE html>
<head>
<link rel="stylesheet" media="screen" href="/style.css" />
</head>
<div id="mainC">
  <div class="message">
    <h1>404</h1>

    ... cut HTML ...

  </div>
</div>

PHP example to query if “127.0.0.2” is listed in AuthBL (no Accept header defaults to JSON):

<?php

$url = 'https://apibl.spamhaus.net/lookup/v1/AUTHBL/127.0.0.2';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer <TOKEN>'
));

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if ( $http_code == 200 ) {
    echo "$response\n";
}
else {
    echo "$http_code\n";
}

Python example to query if the domain “test” is listed in DBL (pip install requests is required):

import requests

headers = {'Authorization': 'Bearer <TOKEN>'}
req = requests.get('https://apibl.spamhaus.net/lookup/v1/DBL/test', headers=headers)

if req.status_code == 200:
   print(req.content.decode('ascii'));
else:
   print(req.status_code)