Skip to content

ClientFence API overview

Everything the admin and client areas do goes through the ClientFence API, so your scripts can do it too: create clients and orders, issue and mark invoices paid, open tickets, suspend services and more. The API reference lists every call.

Role Who calls it How it signs in
admin Your integrations and scripts, as a staff account The staff account’s API key. See Authentication.
client The client area in the browser, and custom themes The client’s browser session. There are no client API keys.
guest Public pages: the store, domain search, sign-in Nothing. Calls that change something need the browser session.

For an integration on your own server, use the admin role with a dedicated staff account.

Each call is a POST to:

https://billing.example.com/api/<role>/<module>/<call>

For example, admin role, invoice module, get_list call: https://billing.example.com/api/admin/invoice/get_list. Send the parameters as a JSON object in the body. The answer is JSON with result and error. See Requests and responses.

Each example lists the first 10 unpaid invoices. Keep the API key in an environment variable or a secret store, never in the code.

Terminal window
curl --silent --user "admin:$CLIENTFENCE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"status": "unpaid", "per_page": 10}' \
https://billing.example.com/api/admin/invoice/get_list
<?php
function clientfence(string $call, array $params = []): mixed
{
$ch = curl_init('https://billing.example.com/api/admin/' . $call);
curl_setopt_array($ch, [
CURLOPT_USERPWD => 'admin:' . getenv('CLIENTFENCE_API_KEY'),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_RETURNTRANSFER => true,
]);
$answer = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!is_array($answer)) {
throw new RuntimeException('No answer from ClientFence');
}
if ($answer['error'] !== null) {
throw new RuntimeException($answer['error']['message'], (int) $answer['error']['code']);
}
return $answer['result'];
}
$invoices = clientfence('invoice/get_list', ['status' => 'unpaid', 'per_page' => 10]);
foreach ($invoices['list'] as $invoice) {
echo $invoice['id'], ' ', $invoice['total'], ' ', $invoice['currency'], "\n";
}
import os
import requests
def clientfence(call, params=None):
answer = requests.post(
f"https://billing.example.com/api/admin/{call}",
json=params or {},
auth=("admin", os.environ["CLIENTFENCE_API_KEY"]),
timeout=30,
).json()
if answer["error"]:
raise RuntimeError(f"{answer['error']['code']}: {answer['error']['message']}")
return answer["result"]
for invoice in clientfence("invoice/get_list", {"status": "unpaid", "per_page": 10})["list"]:
print(invoice["id"], invoice["total"], invoice["currency"])