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.

Access Denied using php xml-api

Discussion in 'cPanel Developers' started by nimrodm, Mar 18, 2014.

  1. nimrodm

    nimrodm Registered

    Joined:
    Mar 18, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    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.
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    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_domainlogin=>$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
     
  3. nimrodm

    nimrodm Registered

    Joined:
    Mar 18, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Hi Dave,
    This is the showmanager function:
    DiskUsage Module Documentation

    It should work... Anyway, Might there be any security settings that might cause this? Something in cpanel or WHM?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,787
    Likes Received:
    665
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  5. nimrodm

    nimrodm Registered

    Joined:
    Mar 18, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    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_domainlogin=>$email_account) );  
    This way I simply get a blank screen. Same as before...
     
  6. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page