Troubleshooting WHMCS API Calls

During the development process, you may need to verify whether your API code is working correctly. To do this, we recommend verifying your code against our documented code examples and enabling debugging to find errors.

For more information and comprehensive API reference guides with use examples, see our Developer Documentation.

Verifying Your 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.

For example:

Example Request (Local API)

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

    $results = localAPI($command, $postData, $adminUsername);
    print_r($results);

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
                    }
                ]
            }
        ]
    }

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 Debugging

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;

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

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

Last modified: October 29, 2024