Shahid Malla

WHMCS API Usage with Real-World Examples

Shahid Malla Shahid MallaDecember 27, 202512 min read
WHMCS API Usage with Real-World Examples

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 client
  • UpdateClient - Modify client details

Orders & Services

  • AddOrder - Place new order
  • GetOrders - List orders
  • GetClientsProducts - Client's services
  • ModuleCreate - Provision service

Invoicing

  • CreateInvoice - Generate invoice
  • GetInvoices - List invoices
  • AddInvoicePayment - 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)
Share this article:
Shahid Malla

About Shahid Malla

Expert

Full 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.