Guides & TutorialsTroubleshootingTroubleshooting CustomizationsTroubleshooting and Debugging WHMCS API Calls

Troubleshooting and Debugging WHMCS API Calls

During the development process, you may need to verify whether your API code is working correctly. You can use several methods to do this.

You can find comprehensive API reference guides with use examples in our Developer Documentation.

API Sample Code

You can verify your code using the sample code in our documentation. This will allow you to check whether it can run without any modifications.

Example Request (Local API)

$command = 'GetUsers';
$postData = array(
    'search' => '[email protected]',
    'responsetype' => 'json',
$adminUsername = 'ADMIN_USERNAME'; // Optional

$results = localAPI($command, $postData, $adminUsername);
Click to copy

Example Response JSON

    "result": "success",
    "totalresults": 1,
    "startnumber": 0,
    "numreturned": 1,
    "users": [
            "id": 1,
            "firstname": "John",
            "lastname": "Smith",
            "email": "[email protected]",
            "datecreated": "2020-12-15 15:29:49",
            "validationdata": "",
            "clients": [
                    "id": 1,
                    "isOwner": true
Click to copy

If the sample code succeeds but your custom code does not, the issue is likely within your own custom code.

If the sample code does not run, the issue may require general troubleshooting.

You can also use the API code samples to begin your custom code and then verify your changes after each modification. If the results begin to include errors, you can easily identify the problems.

API Logging (Advanced)

If you want to debug API calls at a transactional level, you can enable API debugging in the configuration.php file by adding the following line:

$api_enable_logging = true;
Click to copy

This will log the data in the tblapilog table in your WHMCS database.

For WHMCS v7.2 and earlier, create an apilog.txt file in the includes directory and set the permissions to 777  to ensure that the log file works.

After you finish troubleshooting, you must remove the line from your configuration.php file and delete the log file.