Access Denied using php xml-api

nimrodm

Registered
Mar 18, 2014
3
0
1
cPanel Access Level
Reseller Owner
hi,
I am trying to use api function using php xml-api class.
I have done hours of several requests and i keep getting the following result:
Code:
string(122) "{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}} "
My code is:
PHP:
$ip = "my server ip";
$xmlapi = new xmlapi($ip);
$xmlapi->set_port('2083');
$xmlapi->set_output('json');
$root_pass="my user password";

$xmlapi->password_auth("user",$root_pass);
$xmlapi->set_debug();
$xmlapi->get_debug();
$result= $xmlapi->xmlapi_query('showmanager');
var_dump($result);
I'd be happy for any usefull information that might get me going...
I tried the same using curl and it did not work.
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
My code is:
PHP:
$result= $xmlapi->xmlapi_query('showmanager');
I'm not aware of an XML API function called 'showmanager' so that is one reason you may get an error, the other is that cPanel users don't have access to XML API functions other than the 'cpanel' function.

When using port 2083 (cPanel), you'll only have access to API1, API2, (and UAPI which isn't in the XML PHP class yet), so check out their function references and use them like so:

API2:

PHP:
echo $xmlapi->api2_query($account, "Email", "getdiskusage", array(domain=>$email_domain, login=>$email_account) );
API!:

PHP:
echo $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
More info on XML API calls: XML and JSON APIs
API1: API1 Module Listing
API2: Calling API 2 Functions
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
The document you provided shows the "DiskUsage" module, but I do not see that listed anywhere in your script. You may want to use the "API Shell for cPanel" option as documented here to help get a better idea of what modules are available to you:

API Shell for cPanel

Thank you.
 

nimrodm

Registered
Mar 18, 2014
3
0
1
cPanel Access Level
Reseller Owner
Hi,
I don't actualy need the DiskUsage function I just used it for testing purpose because it's simple.

I tried replacing my call to the api2 email module and getdiskusage function and I simply dont get nothing returned...
This is my code now:

PHP:
$ip = "my ip";
$xmlapi = new xmlapi($ip);
$xmlapi->set_port('2083');
$xmlapi->set_output('json');

$root_pass="my pass";

$xmlapi->password_auth("user",$root_pass);
$xmlapi->set_debug();
$email_domain = 'domain.com';
$email_account = 'email_user';
echo $xmlapi->api2_query($account, "Email", "getdiskusage", array(domain=>$email_domain, login=>$email_account) );
This way I simply get a blank screen. Same as before...
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
Hi,
I don't actualy need the DiskUsage function I just used it for testing purpose because it's simple.

I tried replacing my call to the api2 email module and getdiskusage function and I simply dont get nothing returned...
This is my code now:

PHP:
$ip = "my ip";
$xmlapi = new xmlapi($ip);
$xmlapi->set_port('2083');
$xmlapi->set_output('json');

$root_pass="my pass";

$xmlapi->password_auth("user",$root_pass);
$xmlapi->set_debug();
$email_domain = 'domain.com';
$email_account = 'email_user';
echo $xmlapi->api2_query($account, "Email", "getdiskusage", array(domain=>$email_domain, login=>$email_account) );
This way I simply get a blank screen. Same as before...
If you are literally calling:

Code:
$xmlapi->password_auth("user",$root_pass);
than this definitely won't work. "user" should be replaced with the actual username of the user you are trying to connect as and $root_pass will need to be that user's password.