Guides & TutorialsTroubleshooting LicensingTroubleshooting Your License Key is Invalid API Errors

Troubleshooting Your License Key is Invalid API Errors

Symptom

When using the WHMCS API to communicate with your WHMCS installation, you may see a Your license key is invalid error:

<result>error</result>
<message>Your license key is invalid</message>

Cause

This issue occurs when you perform a required license check from a non-web context (for example, the command line interface or a cron job) and the server’s outbound IP address is different than the license's IP address.

WHMCS offers both external and internal APIs. This error typically occurs when you did not choose the best API for the use case.

  • Invoke the internal API in a web context within WHMCS files, hooks, modules, and custom pages.
  • Invoke the external API in non-web contexts and from any other locations.

However, in most cases, daily usage of the Admin Area (a web context) will ensure that a fresh license response is valid for short-term use in non-web contexts.

Solution

For non-web contexts, we recommend making API calls remotely against the website instead of using the localAPI helper function. This ensures that your calls perform any required license check relative to the website request. The license check will reference your website's specific IP address instead of the general outbound IP address of your website's server.

This requires changing your script to send HTTP requests to the API endpoint at https://domain.com/whmcs/includes/api.php, where domain.com is the licensed valid domain and whmcs is the licensed valid directory.

For more information about the external API's authentication requirements, see Authentication.