Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    1

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

    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. #2
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    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).
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    3

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

    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. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    3

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

    Nevermind...the above code does work, I just had a typo in the password! (That's with using port 2082)

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    cPanel/Enkompass Access Level

    Root Administrator

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

    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. #6
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

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

    Quote Originally Posted by cornfeedhobo View Post
    ...

    Code:
    ...  
            $xout = $this->xmlapi->api2_query($cuser, 'Email', 'filterlist', array('test@domain.org'));
    ...
    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-...e_withargs.php

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    cPanel/Enkompass Access Level

    Root Administrator

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

    Its always the most obvious things that elude me...
    Thank you so much!

Similar Threads & Tags
Similar threads

  1. DNS Setup/edit domain forwarding via XML/JSON API
    By abrakadabra in forum Feature Requests for cPanel/WHM
    Replies: 2
    Last Post: 09-02-2011, 06:24 AM
  2. XML or JSON API?
    By Azavia in forum cPanel Developers
    Replies: 3
    Last Post: 05-21-2010, 12:16 PM
  3. Replies: 0
    Last Post: 04-20-2010, 03:37 PM
  4. XML/JSON API & Session Creation using Access Hash
    By jdelsman in forum Feature Requests for cPanel/WHM
    Replies: 0
    Last Post: 02-08-2010, 04:15 PM
  5. XML/JSON API Function to retreive the 'Remote Access Key'
    By shaun in forum Feature Requests for cPanel/WHM
    Replies: 4
    Last Post: 02-08-2010, 02:36 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube