Ready-to-use examples for calling the CWP API from common languages. Replace the server address and YOUR_API_KEY with your own values. See API introduction for creating a key.
Bash (curl)
#!/bin/bash
API="https://server.example.com:2304/v1"
KEY="YOUR_API_KEY"
# Create an account
curl -s -X POST "$API/account/" \
--data-urlencode "key=$KEY" -d "action=add" \
--data-urlencode "domain=example.com" --data-urlencode "user=john" \
--data-urlencode "pass=S3cretPass" --data-urlencode "email=john@example.com" \
--data-urlencode "package=default" --data-urlencode "server_ips=203.0.113.10"
# Suspend it
curl -s -X POST "$API/account/" -d "key=$KEY&action=susp&user=john"
PHP
<?php
function cwp_api(string $function, array $params): array
{
$params['key'] = 'YOUR_API_KEY';
$ch = curl_init("https://server.example.com:2304/v1/{$function}/");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($params),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_SSL_VERIFYPEER => true, // set false only for self-signed test servers
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException('CWP API connection error: ' . curl_error($ch));
}
curl_close($ch);
$data = json_decode($body, true);
if (!is_array($data)) {
throw new RuntimeException('CWP API returned a non-JSON response');
}
if (isset($data['status']) && $data['status'] !== 'OK') {
$msg = $data['msj'] ?? $data['result'] ?? $data['message'] ?? 'unknown error';
throw new RuntimeException('CWP API error: ' . (is_string($msg) ? $msg : json_encode($msg)));
}
return $data;
}
// Create an account
cwp_api('account', [
'action' => 'add', 'domain' => 'example.com', 'user' => 'john',
'pass' => 'S3cretPass', 'email' => 'john@example.com',
'package' => 'default', 'server_ips' => '203.0.113.10',
]);
// One-click login link for the customer
$s = cwp_api('user_session', ['action' => 'list', 'user' => 'john', 'timer' => 1]);
header('Location: ' . $s['msj']['details'][0]['url']);
Python
import requests
API = "https://server.example.com:2304/v1"
KEY = "YOUR_API_KEY"
def cwp_api(function, **params):
params["key"] = KEY
r = requests.post(f"{API}/{function}/", data=params, timeout=120)
r.raise_for_status()
try:
data = r.json()
except ValueError:
raise RuntimeError("CWP API returned a non-JSON response")
if data.get("status", "OK") != "OK":
raise RuntimeError(data.get("msj") or data.get("result") or data.get("message"))
return data
for acc in cwp_api("account", action="list")["msj"]:
print(acc["username"], acc["domain"], acc["status"])
Typical billing integration
| Billing event | API call |
|---|---|
| Order activated | account add (optionally autossl=1) |
| Invoice overdue | account susp |
| Invoice paid | account unsp |
| Upgrade / downgrade | changepack udp (package ID) or account udp (package name) |
| Password reset | changepass udp |
| “Login to panel” button | user_session list → redirect to url |
| Service terminated | account del |
| Usage sync | account list or accountdetail list |
Note: WHMCS and other billing systems have ready-made CWP modules. Create a dedicated API key for them with the WHMCS preset in API Manager, restricted to the billing server’s IP address.