Download the PHP package eugenefvdm/whmcs-api without Composer
On this page you can find all versions of the php package eugenefvdm/whmcs-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package whmcs-api
WHMCS API
A testable WHMCS API designed to run standalone or as part of a Laravel application.
Requirements:
- PHP 8.4
- WHMCS
Installation
Publish the configuration file:
Configuration Settings whmcs.php
WHMCS_URL should be without the trailing slash.
For local installs without a valid TLS certificate (e.g. https://whmcs.test), set WHMCS_VERIFY_SSL=false.
WHMCS_DEFAULT_REG_PERIOD is optional; used by addDomainRegistrationOrder() when no period is passed.
WHMCS Setup
Allow the IP address of the system connecting to WHMCS:
Create API permissions:
Example API permissions required:
- addclient
- addorder
- getclientsdetails
- getclientsdomains
- getorders
- getorderstatuses
- custom list of API calls you are developing
Example, creating a new client with custom fields:
Custom API calls
WHMCS removed the ability to add custom API calls, but there is a hack to get it working again.
An example of a custom API call would be to get a client by their phone number. Let's call this getclientbyphonenumber. At least two steps are required.
- Create a custom API call
- Inject the permission into the database
Example custom API call
Save the example code below here:
includes/api/getclientbyphoneumber.php
Next to use the custom API call getclientbyphonenumber you need to manually update tblapi_roles and add it there.
Also remember to update it every time again you make a changes in the UI because the UI will overwrite the custom API call.
In the example below, the JSON in the database has been updated to include the new API call getclientbyphonenumber.
If you haven't added the PHP file yet, you'll get API Function Not Found.
Examples
Framework Agnostic PHP
Laravel
Use the Whmcs facade after publishing config:
Changelog
See CHANGELOG for more information on what has changed recently.
Features
Connecting to a WHMCS server
Prefer Whmcs::connect() for an isolated client instance — safe for per-tenant credentials or multiple servers in the same request:
setServer() mutates the current instance and is deprecated. The Laravel facade resolves a shared binding, so use connect() when switching servers.
Orders
List orders for a client:
ordersList() normalizes WHMCS's inconsistent single-item vs array responses via WhmcsResponse::list().
For Filament custom-data tables, use ordersPaginator() — returns a LengthAwarePaginator keyed by order id:
Place a domain registration order (wraps AddOrder):
Fetch order statuses for filter options:
Pagination defaults (limitstart, limitnum) are applied only on list endpoints such as getOrders() and getClients() — not on addOrder() or other write calls.
Change plan
Applies a new package to the service via ModuleChangePackage. If the package is linked to a provisioning module, WHMCS will call it.
Error handling
API errors throw WhmcsApiException with the WHMCS action name and parsed response:
Response normalization
WhmcsResponse helpers are available for any nested WHMCS collection:
Testing
Before testing, please ensure you have copied over the .env.example file to .env as the tests use dotenv.
Debugging
Set WHMCS_DEBUG=true in your .env file to enable debugging. When enabled, request and response payloads are sent to Spatie Ray if it is installed.
Running the tests
./vendor/bin/pest
To test custom API actions, use a script such as the following:
sh .scp updateclientaddon.php;./vendor/bin/pest
The .scp file should have a copy command, e.g.:
No errors on API actions but not working
API actions are difficult to troubleshoot if you don't observe the server log file. Only some exceptions, e.g., model problems will be caught by the Try Catch block. So help tail your server log file. For example, if you're using Laravel's Valet's Nginx server, do this:
tail -f ~/.valet/Log/nginx-error.log
Invalid IP 127.0.0.1
If you get Invalid IP 127.0.0.1 that means you haven't allowed WHMCS API access from localhost.
Navigate here: https://whmcs.test/admin/configgeneral.php and make sure you add 127.0.0.1 to API IP Access Restriction.
Invalid or missing credentials
If you get Invalid or missing credentials that means you haven't added API roles and API credentials. Both are required before you can test. Also be sure to add them to your .env file:
Invalid Permissions: API action "addclient" is not allowed
If you get Invalid Permissions: API action "addclient" is not allowed that means,
although you've added API roles and credentials, your roles are not set up properly for the API call.
Revisit roles and the requisite subsection and see where you have to click the checkbox to allow this API call.
Storage folder examples
The storage folder has examples API responses, also used for caching during tests.
Local Editing
For local editing, add this to composer.json:
Then in require section:
Then do this to symlink:
License
MIT
Author
hello (at) eugenefvdm.com
https://eugenefvdm.com
+27 82 309–6710
I am a Laravel, hosting, and WHMCS specialist.
Contact me any time for assistance.