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.

Trouble with account summary API

Discussion in 'cPanel Developers' started by jhyland87, May 28, 2009.

  1. jhyland87

    jhyland87 Well-Known Member

    Joined:
    Dec 8, 2008
    Messages:
    153
    Likes Received:
    0
    Trophy Points:
    16
    I am trying to pull an account summary from one of the accounts, this is the code I have
    PHP:
    <pre>
    <?php
    # cpanel12 - api2_example.php                Copyright(c) 1997-2009 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net

    include("xmlapi.php.inc");

    $ip "blogforfree.net";
    $root_pass "xxxxxxx";

    $account "freeblog";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("blogforf",$root_pass);

    $xmlapi->set_debug(1);
    //print $xmlapi->api2_query($account, "Ftp", "listftpwithdisk" );


    print $xmlapi->api2_query(accountsummary$account);
    ?>
    I get a php error, and access denied, as below
    PHP:

    Warning
    :  Missing argument 3 for xmlapi::api2_query(), called in /home/blogforf/public_html/includes/api2_example.php on line 21 and defined in /home/blogforf/public_html/includes/xmlapi.php.inc on line 112



    Warning
    :  Missing argument 4 for xmlapi::api2_query(), called in /home/blogforf/public_html/includes/api2_example.php on line 21 and defined in /home/blogforf/public_html/includes/xmlapi.php.inc on line 112



    RAW API2 CALL
    :
    freeblog



    QUERY
    :
    https://blogforfree.net:2087/xml-api/cpanel?user=accountsummary&xmlin=%3Ccpanelaction%3E%3Cmodule%3Efreeblog%3C%2Fmodule%3E%3Cfunc%3E%3C%2Ffunc%3E%3Cargs%3E%3C%2Fargs%3E%3C%2Fcpanelaction%3E

    RAW XML:


    1textAccess Denied to accountsummary.


    object(SimpleXMLElement)#2 (3) {
      
    ["apiversion"]=>
      
    string(1"1"
      
    ["type"]=>
      
    string(4"text"
      
    ["data"]=>
      
    object(SimpleXMLElement)#3 (1) {
        
    ["result"]=>
        
    string(32"Access Denied to accountsummary."
      
    }
    }
    SIMPLEXML OBJ:
    Why is that?.. What am I doing wrong?
     
  2. 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
    You are attempting to call an XML API function as if it was an API2 function. I recommend calling the accountsummary XML API function as an XML API function, not as an API2 function.
     
  3. jhyland87

    jhyland87 Well-Known Member

    Joined:
    Dec 8, 2008
    Messages:
    153
    Likes Received:
    0
    Trophy Points:
    16
    I looked in the documentation, I didnt see an answer to this dumb question:..

    .. whats the difference between the API and API2.. :eek:
     
  4. 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
    API1 and API2 are the APIs that the X3 theme for the cPanel interface uses to perform tasks on the cPanel/WHM server. API1 and API2 are for cPanel-related tasks.

    The XML API is an API used to interact with WHM and can be used outside of the cPanel/WHM interface. As a result, it is the basis for most billing applications that interact with cPanel/WHM since it can use some WHM functions like creating accounts etc.

    The XML API can also be used to call API1 and API2 functions from outside the cPanel interface. This allows the XML API to call functions in the cPanel interface as well as some functions of the WHM interface.

    So think of API1 and API2 as cPanel and XML API as WHM. However, if you want to call API1 and API2 from outside the cPanel interface, you can use the XML API as a bridge to do so.
     
  5. jhyland87

    jhyland87 Well-Known Member

    Joined:
    Dec 8, 2008
    Messages:
    153
    Likes Received:
    0
    Trophy Points:
    16
    Awesome :)
    PHP:
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("blogforf",$root_pass);

    $xmlapi->set_debug(1);
    echo 
    '<pre>';
    print 
    $xmlapi->accoutsummary($account);
    Works great, why isnt the BW usage listed though?
     
  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
    Bandwidth usage can be found in a separate function call: showbw

    To show bandwidth for a specific user, use:

    Code:
    .../xml-api/showbw?search=USERNAME&searchtype=user
    ... where USERNAME represents the username whom you want bandwidth information for.
     
  7. jhyland87

    jhyland87 Well-Known Member

    Joined:
    Dec 8, 2008
    Messages:
    153
    Likes Received:
    0
    Trophy Points:
    16
    I need to create this in the xmlapi.php dont I? I dont see showbw anywhere in it

    EDIT: Created it
    PHP:
        public function showbw($username$searchtype) {
            if (!isset(
    $username)) {
                
    error_log("showbw requires that a username is passed to it");
                return 
    0;
            }
            return 
    $this->xmlapi_query("showbw",array(search => $usernamesearchtype => $searchtype));
        }
     
    #7 jhyland87, May 29, 2009
    Last edited: May 29, 2009
  8. 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
    Or you could have just done xmlapi_query. Note, showbw does not require a username. If no parameters are passed, the bandwidth information for all users is returned.
     
Loading...

Share This Page