PHP code example of xililo / whm-api

1. Go to this page and download the library: Download xililo/whm-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xililo / whm-api example snippets




declare(strict_types=1);

use Xililo\WhmApi\Config;
use Xililo\WhmApi\Whm;

$config = new Config(
    host: 'whm.example.com',
    username: 'root',
    token: 'your-api-token',
);

$whm = new Whm($config);

$accounts = $whm->accounts()->list();

foreach ($accounts->data('acct', []) as $account) {
    echo $account['user'] . PHP_EOL;
}

$response = $whm->auth()->createUserSession(
    user: 'example',
    service: 'cpaneld',
);

$url = $response->data('url');

$response = $whm->auth()->getLoginUrl(
    provider: 'cPStore',
    urlAfterLogin: 'https://your-app.example.com/return',
);

$url = $response->data('url');

$accounts = $whm->accounts()->list([
    'search' => 'example',
    'searchtype' => 'domain',
    'searchmethod' => 'exact',
]);

$response = $whm->accounts()->create(
    username: 'example',
    domain: 'example.com',
    password: 'strong-password',
    plan: 'starter',
);

$whm->accounts()->changePackage('example', 'business');

$whm->accounts()->suspend('example', 'Non-payment');
$whm->accounts()->unsuspend('example');

$whm->accounts()->setPassword('example', 'new-password');

$plans = $whm->hostingPlans()->list();

$whm->hostingPlans()->create([
    'name' => 'starter',
    'quota' => 10240,
    'bwlimit' => 102400,
    'maxftp' => 10,
    'maxsql' => 10,
]);

$whm->hostingPlans()->update('starter', [
    'MAX_EMAIL_PER_HOUR' => 200,
]);

$plan = $whm->hostingPlans()->info('starter');

$response->successful();
$response->metadata();
$response->data();
$response->data('acct', []);
$response->reason();
$response->command();
$response->raw();
$response->toArray();