Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    5

    Default xml-api removeacct error

    Hello,
    I can't remove the account using xml-api, however
    creating the account works fine.
    My code:

    PHP Code:
            $params = array(
                
    'user' => 'wat18848',
            );

            
    $config = array(
                
    'config'  => array(
                    
    'host' => $this->_config['host'],
                    
    'user' => $this->_config['username'],
                    
    'password' => $this->_config['password'],
                ),
            );

            
    $cmd 'removeacct';

            
    $xmlapi = new Cpanel_Service_WHM($config);
            
    $result $xmlapi->$cmd($params)->getResponse('array'); 
    But I always get
    Code:
    Array
    (
        [result] => Array
            (
                [0] => Array
                    (
                        [status] => 0
                        [statusmsg] => No user specified
                        [rawout] => 
                    )
    
            )
    
    )
    However, if I run this command directly from cpanel like this:
    https://<host>/cpsess7719510149/xml-api/removeacct?user=<userid>
    It removes the account.
    So what am I doing wrong?

  2. #2
    Member
    Join Date
    Jul 2011
    Posts
    5

    Default Re: xml-api removeacct error

    Nevermind, got it working.. But why doesn't it work if username is passed in an array?

  3. #3
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: xml-api removeacct error

    Hi uzor,

    Glad to here you got it working.

    The reason is that the Cpanel_Service_WHM class currently uses the PHP XML-API client class for backwards compatibility. That methods in that class ('removeacct', 'createacct', etc) usually take ordered parameters and not an arrays or objects.

    Just so anyone reading this isn't confused, uzor is using the cPanel PHP Library, which is bundled with the PHP PublicAPI class.

    You're completely welcome to use that class directly (it's part of the component-oriented design of that library ). However, you might consider creating your object using the PublicAPI class since it abstracts both that class and the Cpanel_Service_cPanel...just a suggestion...you know what's best for your application

    In future versions of that class/library, we hope to add the logic to address such legacy/backwards-compatibility quirks.

    As a side note, I would recommend a slightly different style when retrieving the response result
    PHP Code:
    $response $xmlapi->$cmd($params);

    if (
    $response->validResponse()) {
        
    // the server response was valid and can be parsed to 'array' or
        //  whatever other supported type you want
        
    $result $response->getResponse('array');
    } else {
        
    // the server response was invalid; you can fetch an array of error messages
        
    $result $response->getResponseErrors();

        
    /**
         * or you might want to throw an exception or trigger a warning
         * -- do error handling appropriate for your application here -- 
         * EX: 
         *  $msg = " -- Server responded with bad data --\n";
         *  $msg .= "Error msgs:\n" .implode( "\n", $result );
         *  $msg .= "\nRAW RESPONSE:\n" .$response->getRawResponse() . "\n";
         *  throw new Exception(  $msg );
         */

    It's a little more code but will protect your application from having unexpected errors if the server sends back a mal-formed result.

    Best Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. PHP XML API - output in error log but not on screen!
    By benwiggy in forum cPanel Developers
    Replies: 2
    Last Post: 05-28-2011, 11:23 AM
  2. XML-API function "setacls" documentation error
    By MSTF in forum cPanel Developers
    Replies: 3
    Last Post: 03-04-2011, 08:16 AM
  3. XML-API DNS (killdns response error)
    By paulipv in forum cPanel Developers
    Replies: 2
    Last Post: 07-13-2009, 06:20 PM
  4. XML-API Posible Error
    By paulipv in forum cPanel Developers
    Replies: 1
    Last Post: 07-09-2009, 01:49 PM
  5. XML API: always get login screen, not XML
    By sldff3ald in forum cPanel Developers
    Replies: 3
    Last Post: 09-19-2007, 09:29 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube