API:Internal API

Home / Support / Documentation
From WHMCS Documentation
Jump to: navigation, search

As of Version 4.5, WHMCS has an Internal API that allows you to call any of the API functions offered by WHMCS locally without needing to use CURL.

Internal API calls can be made from any file within WHMCS, be it a product provisioning module, registrar module, gateway module, addon module, an action hook or even a template file.

The syntax for making an internal API call is:

 $results = localAPI($command,$values,$adminuser);

Where $command is the API Function Name to call, $values is an array of the parameters to be passed into the API function, and $adminuser is the Username or ID of the admin user under which to execute the API call.

Note: $adminuser is optional if an admin is already logged in when the call is being made.

The return will be an array containing the same output as a remote API call would contain. So $results['result'] would be the variable to check for success/error.

So a full example of calling the SendEmail API command locally would be as follows:

 <?php
 
 # Set Vars
 $command = 'SendEmail';
 $values = array( 'messagename' => 'Test Template', 'id' => '1', );
 $adminuser = 'DemoAdmin';
 
 # Call API
 $results = localAPI($command,$values,$adminuser);
 if ($results['result']!="success") echo "An Error Occurred: ".$results['result'];
 
 ?>

Simple!