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.

is XML/JSON-API available only to WHM accounts?

Discussion in 'cPanel Developers' started by eschminke, Apr 22, 2010.

  1. eschminke

    eschminke Registered

    Joined:
    Apr 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    My shared host has cPanel 11.25 to manage my account, but I am not a reseller; it is simply my personal account. I have tried to figure out whether or not the API is available for me to use with my type of account. I'm comfortable enough using cURL (as the examples reflect) to know there shouldn't be anything wrong with my code.

    What I'm getting back are HTTP 404 errors. That the document (ex. ./xml-api/applist) was not found.

    Does the API only work for reseller accounts? Is it not enabled by default? Do I have to contact my web host and have them make it available to me? I'd like to know the answers to these questions before I beat my brains in too much trying to resolve this problem I'm having.

    Thanks!
     
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Ok, yes it is available to all accounts, however there are limitations:

    Resellers: Must be used via WHM, applist + all other calls should be available
    users: must be used via port :2083, only the cpanel call (which interfaces to API1 and API2 for pretty much all functionality provided by cPanel/WHM).
     
  3. wanderingstan

    wanderingstan Registered

    Joined:
    Jul 13, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Can you give an example of how a user (non-reseller) would connect to the API? I've tried dozens of combinations but always get an "Access denied" response.

    Code:
      include("xmlapi.php");
    
      $ip = "my-domain.com";
      $my_pass = "mypassword";
      $my_login = "johndoe"
      $account = "johndoe";
    
      $email_user = "somerandomuser";
      $email_password = "adfm90f1m3f0m0adf";
      $email_domain = "somedomain.com";
      $email_query = '10';
    
      $xmlapi = new xmlapi($ip);
      $xmlapi->set_port(2083);
    
      $xmlapi->password_auth($my_login, $root_pass);
      $xmlapi->set_output('json');
    
      $xmlapi->set_debug(1);
      print $xmlapi->api1_query($account, "Email", "addpop", 
        array($email_user, $email_password, $email_quota, $email_domain) 
      );
    This returns
    {"data":{"reason":"Access denied","result":"0"},"type":"text"}

    - For a non-reseller, is the username in password_auth() the same as the $account?
    - In the browser, my cpanel connects to port 2082. Should I be using this port?

    Thanks for any help! For now I'm going back to the scraping method (from this thread), but I'd feel better using the API.
     
  4. wanderingstan

    wanderingstan Registered

    Joined:
    Jul 13, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Nevermind...the above code does work, I just had a typo in the password! (That's with using port 2082)
     
  5. cornfeedhobo

    cornfeedhobo Member

    Joined:
    Dec 2, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I am having similar troubles. I am able to connect and get a response with the cPanel account's filters, but not the User filter that I am requesting. Any ideas?
    Don't mind the roundcube stuff, I

    Code:
            require_once 'lib/xmlapi.inc.php';
            
            $chost = 'localhost';
            $cport = 2083;
            $cuser = 'johndoe';
            $cpass = 'password';
            
            // Setup the xmlapi connection
            $this->xmlapi = new xmlapi($chost);
            $this->xmlapi->set_port($cport);
            $this->xmlapi->password_auth($cuser, $cpass);
            $this->xmlapi->set_output('json');
            $this->xmlapi->set_debug(1);
            
            $xout = $this->xmlapi->api2_query($cuser, 'Email', 'filterlist', array('test@domain.org'));
    
    The output I am getting is correctly formatted, but it is the Account wide filter, not the email I have given and the docs say it can give.

    {"cpanelresult":{"data":[{"rules":[{"part":"$header_from:","val":"domain.com","opt":"or","match":"contains"}],"unescaped":"1","filtername":"Master","actions":[{"dest":"/dev/null","action":"save"}]}],"event":{"result":1},"module":"Email","apiversion":2,"func":"filterlist"}}
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    There's your problem :).

    API2 (unlike API1) requires named arguments. You are just passing the email address in the array, not the name of the argument mentioned in the document you linked to.

    A code sample for passing API2 arguments via the XML API like you're doing can be found at: https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/api2_example_withargs.php
     
  7. cornfeedhobo

    cornfeedhobo Member

    Joined:
    Dec 2, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Its always the most obvious things that elude me...
    Thank you so much!
     
Loading...

Share This Page