PHP code example of ayowande / cpanel-api

1. Go to this page and download the library: Download ayowande/cpanel-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/ */

    

ayowande / cpanel-api example snippets


use ayowande\Cpanel\Cpanel;

$cpanel = new Cpanel(
    'example.com',    // cPanel server hostname
    'username',       // cPanel username
    2083,             // Port (usually 2083 for SSL)
    'your-api-token'  // cPanel API token
);

$response = $cpanel->get('/json-api/listaccts', [
    'api.version' => 1
]);

echo $response;

$response = $cpanel->post('/json-api/createacct', [
    'api.version' => 1,
    'username' => 'newuser',
    'domain' => 'newdomain.com',
    'plan' => 'default'
]);

echo $response;

try {
    $response = $cpanel->get('/json-api/listaccts', [
        'api.version' => 1
    ]);

    echo $response;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}