Login WHM via Remote Access Key

Labadora

Registered
Jul 1, 2017
1
0
1
Egypt
cPanel Access Level
Root Administrator
hello
I want to file ex. php whatever to access whm via Remote Access Key
pls i don't want to any doc
just i want to file using curl to call whm via hash code "Remote Access Key" and secure
regards ,,
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello,

Here's an example of how to authenticate as root to WHM using the access hash in a PHP script:

Code:
<?
$whmusername = "root";
 
# The contents of /root/.accesshash
$hash = "accesshashhere";
 
$query = "https://127.0.0.1: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);
if ($result == false) {
    error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
}
curl_close($curl);
 
print $result;
?>
This is fully documented at:

Guide to API Authentication - Access Hash Authentication - Software Development Kit - cPanel Documentation

Could you review this document and let us know if you have any specific questions?

Thanks!