darthsoup / php-whmcs-api
WHMCS API client for PHP
Requires
- php: ^7.4|^8.0.2
- ext-json: *
- php-http/client-common: ^2.6
- php-http/discovery: ^1.17
- php-http/httplug: ^2.4
- psr/http-client-implementation: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.1 || ^2.0
- symfony/options-resolver: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- http-interop/http-factory-guzzle: ^1.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^8.5 || ^9.5
README
A simple, PSR-7 compatible WHMCS API client for PHP, inspired by GitLabPHP/Client.
Requirements
- PHP ^7.4 | ^8.0 | ^8.1 | ^8.2 | ^8.3 | ^8.4
- PHP extensions:
curl,json,mbstring
Installation
composer require darthsoup/php-whmcs-api guzzlehttp/guzzle:"^7.8" http-interop/http-factory-guzzle:"^1.0"
Usage
Initialize the client
<?php require_once __DIR__ . '/vendor/autoload.php'; $client = new \DarthSoup\WhmcsApi\Client(); // Authenticate with API identifier and secret $client->authenticate('your_identifier', 'your_secret', \DarthSoup\WhmcsApi\Client::AUTH_API_CREDENTIALS); // Or authenticate with login credentials (username and password, plain text) $client->authenticate('your_username', 'your_password', \DarthSoup\WhmcsApi\Client::AUTH_LOGIN_CREDENTIALS); // Set the URL to your WHMCS instance $client->url('https://<your_whmcs_instance_url>');
API access key
If your WHMCS instance has an $api_access_key set in configuration.php, pass it via accessKey() during client setup:
$client = new \DarthSoup\WhmcsApi\Client(); $client->authenticate('your_identifier', 'your_secret', \DarthSoup\WhmcsApi\Client::AUTH_API_CREDENTIALS); $client->accessKey('your_access_key'); $client->url('https://<your_whmcs_instance_url>');
The access key is automatically appended to every API request body.
Endpoints
| Name | Status |
|---|---|
| Addons | Complete |
| Affiliates | Complete |
| Authentication | Complete |
| Billing | Complete |
| Client | Complete |
| Domains | Complete |
| Orders | Complete |
| Products | Complete |
| Servers | Complete |
| Service | Complete |
| Support | Incomplete |
| System | Complete |
| Ticket | Incomplete |
| Users | Complete |
Examples
Get clients
$client->client()->getClients(['search' => 'firstname']);
Get all orders
$client->orders()->getOrders();
Call a custom API route
If your WHMCS instance exposes custom API routes, you can call them directly without extending the library:
$parameters = ['foo' => 'bar']; $client->custom()->yourCustomApiName($parameters);
More examples can be found in the /examples directory.
Disclaimer
This client follows the WHMCS API documentation. Note that parts of the official API documentation are incomplete or inconsistently documented — please verify behaviour against your WHMCS version.
Support
License
This package is released under the MIT License. See the bundled LICENSE file for details.