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.
Three roles
Section titled “Three roles”| 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.
The URL of a call
Section titled “The URL of a call”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.
A first request
Section titled “A first request”Each example lists the first 10 unpaid invoices. Keep the API key in an environment variable or a secret store, never in the code.
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<?phpfunction 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";}Python
Section titled “Python”import osimport 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"])- Authentication: API keys, staff permissions and the addresses keys work from.
- Requests and responses: errors, paged lists, dates and limits.
- Common tasks: the calls for the jobs integrations do most.
- To add calls of your own, write a module.

