The WHMCS API lets you integrate external systems, build custom dashboards, and automate complex workflows. Here's how to use it effectively.
API Authentication
Method 1: API Credentials
Create API credentials in Setup → Staff Management → API Credentials. Provides identifier and secret for external access.
Method 2: Admin User
Use admin username/password for internal scripts. Less secure but simpler for server-side code.
Making API Calls
External Call (PHP)
$postfields = [
'identifier' => 'YOUR_API_ID',
'secret' => 'YOUR_API_SECRET',
'action' => 'GetClients',
'responsetype' => 'json',
];
$ch = curl_init('https://yourdomain.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$result = json_decode($response, true);
Internal Call (within WHMCS)
$result = localAPI('GetClients', [
'limitstart' => 0,
'limitnum' => 25
]);
Common API Actions
Client Management
GetClients- List all clients-
GetClientsDetails- Get specific client AddClient- Create new clientUpdateClient- Modify client details
Orders & Services
AddOrder- Place new orderGetOrders- List ordersGetClientsProducts- Client's servicesModuleCreate- Provision service
Invoicing
CreateInvoice- Generate invoiceGetInvoices- List invoicesAddInvoicePayment- Record payment
Real-World Examples
Sync Clients to CRM
$clients = localAPI('GetClients', ['limitnum' => 1000]);
foreach ($clients['clients']['client'] as $client) {
$crmApi->createOrUpdate([
'email' => $client['email'],
'name' => $client['firstname'] . ' ' . $client['lastname'],
'company' => $client['companyname'],
'revenue' => getTotalSpent($client['id'])
]);
}
Create Order Programmatically
$result = localAPI('AddOrder', [
'clientid' => 123,
'pid' => [1], // Product ID
'domain' => ['example.com'],
'billingcycle' => ['annually'],
'paymentmethod' => 'paypal'
]);
Best Practices
- Use HTTPS for all API calls
- Implement rate limiting on your end
- Handle errors gracefully
- Log API interactions for debugging
- Use localAPI when possible (faster, no auth overhead)
About Shahid Malla
ExpertFull Stack Developer with 10+ years of experience in WHMCS development, WordPress, and server management. Trusted by 600+ clients worldwide for hosting automation and custom solutions.