Info
As of WHMCS 7.8, modules can implement the List Accounts functionality to offer sync functionality to administrative users (Server Sync Tool).
To allow WHMCS to import accounts from a remote system, meta data fields, and a new function must be included in the module files.
use WHMCS\Service\Status;
...
function mymodule_MetaData()
{
return array(
// The display name of the unique identifier to be displayed on the table output
'ListAccountsUniqueIdentifierDisplayName' => 'Domain',
// The field in the return that matches the unique identifier
'ListAccountsUniqueIdentifierField' => 'domain',
// The config option indexed field from the _ConfigOptions function that identifies the product on the remote system
'ListAccountsProductField' => 'configoption1',
);
}
function mymodule_ListAccounts(array $params)
{
$accounts = [];
try {
// Call the remote api to obtain the list of accounts. Use the values provided by
// WHMCS in `$params`. (https://developers.whmcs.com/provisioning-modules/module-parameters/)
//$data = mymodule_call($params, 'listaccounts');
foreach ($data as $account) {
$accounts[] = [
// The remote accounts email address
'email' => '[email protected]',
// The remote accounts username
'username' => 'john',
// The remote accounts primary domain name
'domain' => 'example.net',
// This can be one of the above fields or something different.
// In this example, the unique identifier is the domain name
'uniqueIdentifier' => 'example.net',
// The accounts package on the remote server
'product' => 'Basic',
// The remote accounts primary IP Address
'primaryip' => '1.2.3.4',
// The remote accounts creation date (Format: Y-m-d H:i:s)
'created' => '2019-07-02 13:15:00',
// The remote accounts status (Status::ACTIVE or Status::SUSPENDED)
'status' => Status::ACTIVE,
];
}
// When returning the accounts, ensure that you return a success as a boolean
// and accounts as an array.
return [
'success' => true, // Boolean value
'accounts' => $accounts,
];
} catch (Exception $e) {
return [
'success' => false, // Boolean value
'error' => $e->getMessage(),
];
}
}A list of Module Parameters passed to this function can be found here.
WHMCS expects the following parameters returned for each account:
| Parameter | Type | Description |
|---|---|---|
| string | The remote accounts email address. | |
| username | string | The remote accounts username. |
| domain | string | The remote accounts primary domain name. |
| uniqueIdentifier | string | If one is not provided by the remote server, we recommend setting this to the domain name. |
| product | string | The accounts package on the remote server. |
| primaryip | string | The remote accounts primary IP Address. |
| created | string | The remote accounts creation date. (Format: Y-m-d H:i:s) |
| status | string | The remote accounts status. (WHMCS\Service\Status::ACTIVE or WHMCS\Service\Status::SUSPENDED) |