Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting account quota via XMLAPI

Discussion in 'cPanel Developers' started by greenbutterfly, Jun 12, 2017.

Tags:
  1. greenbutterfly

    greenbutterfly Registered

    Joined:
    Jun 12, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  3. greenbutterfly

    greenbutterfly Registered

    Joined:
    Jun 12, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page