greenbutterfly

Registered
Jun 12, 2017
2
0
1
Australia
cPanel Access Level
Website Owner
I'm trying to use the XMLAPI PHP (v1.0.13 obtained off the github source) class to obtain the quota for an e-mail account on the host that I'm running.

I've got the user, domain, password, port, etc. all configured correctly AFAIK, and set for JSON output using curl.

The line I'm calling is: $cpanel->xmlapi_query('get_pop_quota', array('email' => $emailaddress, 'domain' => Domain(), 'as_bytes' => '0')) where $emailaddress is a filtered out account name and Domain() is a function that returns the domain of the website.

When running, I get a URL of "http://<domain>:2082/json-api/get_pop_quota", and that produces a 404 error. Dropping the url manually into my browser gets me
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}

I'm new to this PHP module and have found it difficult to find out information about how to use it on this site... everything refers to UAPI but how does that correspond to the xmlapi in the PHP file?

But more importantly, I've searched on this but found little to actually help me understand how to resolve this, so some pointers to any relevant info would be very much appreciated. Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
When running, I get a URL of "http://<domain>:2082/json-api/get_pop_quota", and that produces a 404 error. Dropping the url manually into my browser gets me
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
Hello,

It looks like you are missing the session number in the URL. For instance, here's out the URL would look when using the UAPI function in a browser:

Code:
https://hostname.example.com:2083/cpsess##########/execute/Email/get_pop_quota?email=user&domain=example.com&as_bytes=1
Information on API authentication is available at:

Guide to API Authentication - Software Development Kit - cPanel Documentation

Thank you.
 

greenbutterfly

Registered
Jun 12, 2017
2
0
1
Australia
cPanel Access Level
Website Owner
Thanks for the reply, but I'm confused, because I've already got this code which I thought would handle that authentication:
$cpanel = new xmlapi("my_login_user_for_cPanel", "my_password", "my_domain");
$cpanel->set_port(2082);
$cpanel->set_http_client('curl');
$cpanel->set_output('json');
$cpanel->set_user('my_login_user_for_cPanel');
$cpanel->set_password("my_password");
$cpanel->set_host('my_domain');

I ended up having to put in the user, password and domain twice... I'm assuming because the setting of some of the other bits resets something. Right now, I'm using port 2082 as I'm still organising SSL certification... once done I'll switch it to 2083.

From reading through the info, I'm guessing it's not enough, though. I need to separately tell it to log in via a call to the API, is that correct?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Thanks for the reply, but I'm confused, because I've already got this code which I thought would handle that authentication:
$cpanel = new xmlapi("my_login_user_for_cPanel", "my_password", "my_domain");
$cpanel->set_port(2082);
$cpanel->set_http_client('curl');
$cpanel->set_output('json');
$cpanel->set_user('my_login_user_for_cPanel');
$cpanel->set_password("my_password");
$cpanel->set_host('my_domain');
Hello,

You can try using the PHP example for the single sign on functionality documented at:

Guide to API Authentication - Single Sign On - Software Development Kit - cPanel Documentation

Let us know if that helps.

Thank you.