Page 3 of 8 FirstFirst 12345 ... LastLast
Results 31 to 45 of 108

Thread: XML API PHP Class version 1.0

  1. #31
    Member
    Join Date
    Jan 2010
    Posts
    7

    Default

    Hi Matt,

    I was missing: $xmlapi->set_output('array');

    Everything is fine now.

  2. #32
    Registered User
    Join Date
    Jan 2010
    Posts
    1

    Lightbulb return error

    Great class

    Thanks alot
    Last edited by mshannaq; 01-16-2010 at 05:31 AM.

  3. #33
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Default API Newbie here :)

    I have a Reseller account (i.e. have access to WHM, reselling cpanel accounts) and I'm having trouble trying to understand how to use the API PHP Class.

    What I want to accomplish is a customer login system where my customers log in and they see, among other things, a table featuring their Disk Used, Disk Limit, Bandwidth Used and Bandwidth Limit.

    I'm fine with developing the login system etc... I can even get "accountsummary" to display the data of an account I need, however it displays ALL the account summary output (in SimpleXML) and I don't know how to limit it to certain data.

    My PHP code is as follows:

    Code:
    <?php
    
    include("xmlapi.php");
    
    $ip = "localhost";
    
    # The access has can be found on your server under WHM's "Setup remote access hash" section or at /root/.accesshash
    $root_hash = 'MY HASH CODE HERE';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->hash_auth("MY WHM ACCOUNT USERNAME",$root_hash);
    $xmlapi->return_xml(1);
    $xmlapi->set_debug(1);
    
    $username = CpanelUsername;
    
    $xmlapi->accountsummary($username);
    
    print $xmlapi->accountsummary($username);
    
    ?>
    and it displays this:

    Code:
    <accountsummary>
      <acct>
        <disklimit>200M</disklimit>
        <diskused>63M</diskused>
        <domain>domain.com</domain>
        <email>email@domain.com</email>
        <ip>IP</ip>
        <maxaddons>100</maxaddons>
        <maxftp>100</maxftp>
        <maxlst>100</maxlst>
        <maxparked>100</maxparked>
        <maxpop>100</maxpop>
        <maxsql>100</maxsql>
        <maxsub>100</maxsub>
        <owner>OWNER</owner>
        <partition>home</partition>
        <plan>PLAN</plan>
        <shell>/usr/local/cpanel/bin/noshell</shell>
        <startdate>STARTDATE</startdate>
        <suspended>0</suspended>
        <suspendreason>not suspended</suspendreason>
        <suspendtime></suspendtime>
        <theme>x3</theme>
        <unix_startdate>UNIX_STARTDATE</unix_startdate>
        <user>USER</user>
      </acct>
      <status>1</status>
      <statusmsg>Ok</statusmsg>
    </accountsummary>
    How on earth do I display, for example, only the data within the <diskused></diskused> tags? I have search for hours on more than one occasion on how to do this, and the only thing I can find are replies to similar questions suggesting they read the cPanel API documentation or SimpleXML Documentation. I have gone through these as best as I can, but I still don't know the answer to my question. These documentations either don't answer my question, or I'm just not understanding it.

    I've tried things like:

    Code:
    $diskused =  $xmlapi->accountsummary->acct->diskused;
    
    print $diskused;
    and

    Code:
    print $xmlapi->accountsummary($username)->diskused;
    but none of these work.

    I'd really appreciate any help any of you may be able to offer.

    Many thanks,


    Andrew

  4. #34
    Member
    Join Date
    Apr 2008
    Posts
    26

    Default

    Quote Originally Posted by andrew_syd View Post
    I have a Reseller account (i.e. have access to WHM, reselling cpanel accounts) and I'm having trouble trying to understand how to use the API PHP Class.

    What I want to accomplish is a customer login system where my customers log in and they see, among other things, a table featuring their Disk Used, Disk Limit, Bandwidth Used and Bandwidth Limit.

    I'm fine with developing the login system etc... I can even get "accountsummary" to display the data of an account I need, however it displays ALL the account summary output (in SimpleXML) and I don't know how to limit it to certain data.

    My PHP code is as follows:

    Code:
    <?php
    
    include("xmlapi.php");
    
    $ip = "localhost";
    
    # The access has can be found on your server under WHM's "Setup remote access hash" section or at /root/.accesshash
    $root_hash = 'MY HASH CODE HERE';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->hash_auth("MY WHM ACCOUNT USERNAME",$root_hash);
    $xmlapi->return_xml(1);
    $xmlapi->set_debug(1);
    
    $username = CpanelUsername;
    
    $xmlapi->accountsummary($username);
    
    print $xmlapi->accountsummary($username);
    
    ?>
    and it displays this:

    Code:
    <accountsummary>
      <acct>
        <disklimit>200M</disklimit>
        <diskused>63M</diskused>
        <domain>domain.com</domain>
        <email>email@domain.com</email>
        <ip>IP</ip>
        <maxaddons>100</maxaddons>
        <maxftp>100</maxftp>
        <maxlst>100</maxlst>
        <maxparked>100</maxparked>
        <maxpop>100</maxpop>
        <maxsql>100</maxsql>
        <maxsub>100</maxsub>
        <owner>OWNER</owner>
        <partition>home</partition>
        <plan>PLAN</plan>
        <shell>/usr/local/cpanel/bin/noshell</shell>
        <startdate>STARTDATE</startdate>
        <suspended>0</suspended>
        <suspendreason>not suspended</suspendreason>
        <suspendtime></suspendtime>
        <theme>x3</theme>
        <unix_startdate>UNIX_STARTDATE</unix_startdate>
        <user>USER</user>
      </acct>
      <status>1</status>
      <statusmsg>Ok</statusmsg>
    </accountsummary>
    How on earth do I display, for example, only the data within the <diskused></diskused> tags? I have search for hours on more than one occasion on how to do this, and the only thing I can find are replies to similar questions suggesting they read the cPanel API documentation or SimpleXML Documentation. I have gone through these as best as I can, but I still don't know the answer to my question. These documentations either don't answer my question, or I'm just not understanding it.

    I've tried things like:

    Code:
    $diskused =  $xmlapi->accountsummary->acct->diskused;
    
    print $diskused;
    and

    Code:
    print $xmlapi->accountsummary($username)->diskused;
    but none of these work.

    I'd really appreciate any help any of you may be able to offer.

    Many thanks,


    Andrew
    It's quite simple actually. Here is a very basic example that echoes out the domain name of each account

    Code:
    // get list of accounts
    $accounts = $xmlapi->listaccts();
    
    // create SimpleXML object to loop through later
    $xml2 = new SimpleXMLElement($accounts);
    
    	foreach ($xml2->acct as $account) {
    	$mydomain = $account->domain;
            echo $mydomain;
            }

  5. #35
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Default

    Quote Originally Posted by larwilliams View Post
    It's quite simple actually. Here is a very basic example that echoes out the domain name of each account

    Code:
    // get list of accounts
    $accounts = $xmlapi->listaccts();
    
    // create SimpleXML object to loop through later
    $xml2 = new SimpleXMLElement($accounts);
    
    	foreach ($xml2->acct as $account) {
    	$mydomain = $account->domain;
            echo $mydomain;
            }
    Wow thank you so much, that's so easy. Much appreciated...

  6. #36
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Feb 2003
    Location
    Gothenburg, Sweden
    Posts
    329
    cPanel/WHM Access Level

    DataCenter Provider

    Default

    Two api2 functions that I've added to my version of the xmlapi class for those who are looking for a way to check "mxcheck" (remote, local, auto, backup etc) and to set it.

    Code:
    // This API function fetches an mx list for the supplied domain and specific user
    	public function listmxs($username, $args = null) {
    		if ( (!isset($username)) || (!isset($args)) ) {
    			error_log("stat requires that a username and options are passed to it");
    			return false;
    		}
    		return $this->api2_query($username, 'Email', 'listmxs', $args);
    	}
    	
    	// This API function sets mx check (local, remote, backup) for a domain and user.
    	public function setmxcheck($username, $args = null) {
    		if ( (!isset($username)) || (!isset($args)) ) {
    			error_log("stat requires that a username and options are passed to it");
    			return false;
    		}
    		return $this->api2_query($username, 'Email', 'setmxcheck', $args);
    	}
    }

    twitter: oderland_david

  7. #37
    Member MattDees's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default v1.0.5 released

    Patched for version 1.0.5.

    There are a couple of fixes.

    http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.5.tar.gz

    Changelog:

    * 1.0.5:
    * fix bug where api1_query and api2_query would not return JSON data
    *
    * 1.0.4:
    * set_port will now convert non-int values to ints
    *
    * 1.0.3:
    * Fixed issue with set_auth_type using incorrect logic for determining acceptable auth types
    * Suppress non-UTF8 encoding when using curl
    *
    * 1.0.2:
    * Increased curl buffer size to 128kb from 16kb
    * Fix double encoding issue in terminateresellers()
    *
    * 1.0.1:
    * Fixed use of wrong variable name in curl error checking
    * adjust park() to use api2 rather than API1
    *
    * 1.0
    * Added in 11.25 functions
    * Changed the constructor to allow for either the "DEFINE" config setting method or using parameters
    * Removed used of the gui setting
    * Added fopen support
    * Added auto detection for fopen or curl (uses curl by default)
    * Added ability to return in multiple formats: associative array, simplexml, xml, json
    * Added PHP Documentor documentation for all necessary functions
    * Changed submission from GET to POST
    Matt Dees

  8. #38
    Member
    Join Date
    Nov 2004
    Posts
    26

    Default

    Hi,

    How to use this api ? I tried to run the api2_example.php file and just got this:

    Code:
    {"cpanelresult":{"data":[],"event":{"result":1},"module":"Email","apiversion":2,"func":"listpopswithdisk"}}
    I just want to create and delete a forwarding email address in a specific cpanel account. How to do it using this xml api ?

    Thanks.

  9. #39
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default How to use XML or JSON api

    Hi TapanB

    You can find the documentation of the XML and JSON apis here:
    XML and JSON APIs

    Specifically, api2_example.php will list all pop addresses with their disk usage. For this call to work you must provide cPanel user account to check against ($account='somecpanelusername'). If the cpanel user has no email accounts setup for their domain, the result will be an empty 'data' block, but with a 1 in the 'event'=>'result' block. This indicates that the system recognized your query, but doesn't have anything to show you for the variables you've provided. The same result will return if you provide a user that doesn't exist on that system.

    Code:
    $account='dave';  //my username is dave and my domain is dave.test;
    will return this, if I have one email account for tester@dave.test
    Code:
    {"cpanelresult":{"data":[{"diskquota":250,"humandiskquota":"250 MB","user":"tester","_diskused":0,"humandiskused":"None","_diskquota":262144000,"txtdiskquota":250,"diskusedpercent":0,"diskusedpercent20":0,"login":"tester@dave.com","domain":"dave.com","diskused":0,"email":"tester@dave.com"}],"event":{"result":1},"module":"Email","apiversion":2,"func":"listpopswithdisk"}}
    if you which to have XML output, just set
    Code:
    $xmlapi->set_output('xml');  //instead of json
    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 Requests

  10. #40
    Member
    Join Date
    Nov 2004
    Posts
    26

    Default

    Quote Originally Posted by cPanelDavidN View Post
    Hi TapanB

    You can find the documentation of the XML and JSON apis here:
    XML and JSON APIs

    Specifically, api2_example.php will list all pop addresses with their disk usage. For this call to work you must provide cPanel user account to check against ($account='somecpanelusername'). If the cpanel user has no email accounts setup for their domain, the result will be an empty 'data' block, but with a 1 in the 'event'=>'result' block. This indicates that the system recognized your query, but doesn't have anything to show you for the variables you've provided. The same result will return if you provide a user that doesn't exist on that system.

    Code:
    $account='dave';  //my username is dave and my domain is dave.test;
    will return this, if I have one email account for tester@dave.test
    Code:
    {"cpanelresult":{"data":[{"diskquota":250,"humandiskquota":"250 MB","user":"tester","_diskused":0,"humandiskused":"None","_diskquota":262144000,"txtdiskquota":250,"diskusedpercent":0,"diskusedpercent20":0,"login":"tester@dave.com","domain":"dave.com","diskused":0,"email":"tester@dave.com"}],"event":{"result":1},"module":"Email","apiversion":2,"func":"listpopswithdisk"}}
    if you which to have XML output, just set
    Code:
    $xmlapi->set_output('xml');  //instead of json
    Hello,

    I checked the API doc but it does'nt shows how to create/delete Forwarding email addresses. Please help.

    Thanks.

  11. #41

    Default

    Forwarding email addresses is not a WHM function. You should use a cPanel class instead.

  12. #42
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default create/delete email forward

    If you're wanting to use the xml-api:

    To create an email forward you must make this api2 call:
    ApiEmail < ApiDocs < TWiki

    To delete an email forward you must make an api1 call to Email::delforward, which, to my surprise, is currently undocumented (but will be the future )

    Code:
    https://yourserver:2083/xml-api/cpanel?
    cpanel_xmlapi_apiversion=1
    &cpanel_xmlapi_module=Email
    &cpanel_xmlapi_func=delforward
    arg-0=someone%40dave.com%3Dnewdestination%40dave.com
    The key here is that the first argument (and only argument) to pass to delforward is a string that represents the relationship of the target address (inbound address) and the destination address (where the email gets forwarded to).

    if you're using the XMLAPI.php client class, an example usage would be:
    Code:
    include("xmlapi.php");
    $ip = "192.168.1.1";
    $account_pass = "secret_passwd";
    $account = "dave";
    $foward_to_kill = 'someone@dave.com=newdestination@dave.com';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);
    $xmlapi->set_output("xml");
    $xmlapi->set_port('2083');
    
    $result = $xmlapi->api1_query($account, "Email", "delforward", array($forward_to_kill) );
    Regards,
    -Dave
    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 Requests

  13. #43
    Member
    Join Date
    Nov 2004
    Posts
    26

    Default

    Hi,

    Ok go deleted working also.

    Thanks.
    Last edited by TapanB; 03-19-2010 at 06:21 AM.

  14. #44
    Member
    Join Date
    Nov 2004
    Posts
    26

    Default

    Hello,

    Got add working.

    Thanks.
    Last edited by TapanB; 03-19-2010 at 06:21 AM.

  15. #45
    Registered User
    Join Date
    Jun 2005
    Posts
    1

    Default

    Hi everyone. i'm having trouble with creating accounts via xml api. Account creation is fine but i want to create account using packages i already created.

    PHP Code:
    $xml        =    simplexml_load_string($xmlData);
    foreach(
    $xml as $paketler)
    {
        
    $paketAdi    =    $paketler->name;
        echo    
    "<option value=\"$paketAdi\">$paketAdi</option>";

    fetching packages like above and process this way ;
    PHP Code:
            $paket        =    $_POST["paket"];
            
    $acct = array( username => $usernamepassword => $passworddomain => $domainpkgname => $paket); 

    account creation is successful but package is setting "default". How can i create account with packages ( created in whm )

    thanks so much. and sorry about my English :/

Page 3 of 8 FirstFirst 12345 ... LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-04-2011, 09:52 AM
  2. XML API class works with a WHM cPanel reseller account?
    By bcosmo in forum cPanel Developers
    Replies: 1
    Last Post: 03-17-2010, 09:33 AM
  3. Install wildcard ssl using XML API class
    By tomdchi in forum cPanel Developers
    Replies: 4
    Last Post: 02-21-2010, 07:58 PM
  4. WHM XML API ready to use class
    By arash_hemmat in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 07-18-2008, 05:03 AM