API2, authenticate with api key instead of root user/pass?

jspicher

Member
May 19, 2011
5
0
51
Hey guys,

I'm using the cpanel xmlapi to automatically setup addon domains and l was wondering how l could use the cpanel api key to authenticate instead of the root username/password for the server.

Here's the current code l'm using:

PHP:
<?php
$subdomain = 'addondomain.com';
$username = 'myusername';
$password = 'mypassword';


require_once('xmlapi.php');

$xmlapi = new xmlapi('184.154.XXX.138');
$xmlapi->password_auth("root", 'ROOT_PASSWORD');

$r = $xmlapi->api2_query($username, "AddonDomain", "addaddondomain", array(subdomain => $subdomain, newdomain => $subdomain, dir => $subdomain, pass => $password));

echo '<pre>';
print_r($r);

?>
Any help would be greatly appreciated!
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
Hi jspicher,

I believe you're referring to the root accesshash. You can use that within PHP and with the xmlapi client class as follows

PHP:
$hash = file_get_contents('/path/to/file/.accesshash');

$xmlapi->set_user('root');
$xmlapi->set_hash($hash);
Regards,
-DavidN