İsmet
İsmet

Reputation: 105

WHM api request return "Token denied" :/

I try get account list on WHM. But my access code doesn't work. Request url return;

{"cpanelresult":{"apiversion":"2","error":"Token denied","data":{"reason":"Token denied","result":"0"},"type":"text"}}

My code is;

$url="https://raxxun.net:2087/cpsess421xxx09/json-api/listaccts?api.version=1&search=albxxros&searchtype=user";

$cek=file_get_contents($url);
echo $cek;

I get as token code cpsess421xxx09 in WHM. Where are my wrong?

Upvotes: 1

Views: 2163

Answers (1)

jagjeet
jagjeet

Reputation: 377

You will need following server details to get all accounts –

WHM login URL

WHM usernmae

WHM accesshash key

Below is the API you can use if you have upper details :-

    $server_login_link = 'WHM login url';
    $whmusername = 'WHM username ';
    $hash = 'your access hash key for WHM';
    $query = "https://$server_login_link:2087/json-api/listaccts?api.version=1";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

    $header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$hash);
    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
    curl_setopt($curl, CURLOPT_URL, $query);

    $result = curl_exec($curl);
    print_r(json_decode($result));

NOTE:- For Accesshash key , New or already generated Access key can get from here:- WHM > Remote Access Key area and the Access Key located there. or it should be at this path “/usr/local/cpanel/bin/realmkaccesshash

Upvotes: 1

Related Questions