Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Need a basic example of working with cPanel's XML API PHP Class

Discussion in 'cPanel Developers' started by daveconners, Nov 6, 2013.

  1. daveconners

    daveconners Registered

    Joined:
    Nov 6, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Well I've search high and low and still cant get any result. I am trying to create an addon domain (I have a shared hosting account) this sample code is from github I would appreciate it if someone could explain this code line by line.

    PHP:
    <?php

    include '../xmlapi.php';

    $ip getenv('REMOTE_HOST');
    $root_pass getenv('REMOTE_PASSWORD');

    $domain "somedns.com";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_http_client('curl');
    $xmlapi->set_port(2086);
    $xmlapi->set_debug(1);

    print 
    $xmlapi->adddns($domain,$ip);

    ?>
     
  2. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    83
    cPanel Access Level:
    Root Administrator
    Code:
    include '../xmlapi.php';  // Includes the xml api support
    $ip = getenv('REMOTE_HOST'); //set IP to whatever your REMOTE_HOST is ... this should be your cpanel server's ip
    $root_pass = getenv('REMOTE_PASSWORD'); // root password for cpanel server
    $domain = "somedns.com";  // domain to add
    $xmlapi = new xmlapi($ip); //creates a new xmlapi call specified to the ip address you gave it
    $xmlapi->password_auth("root",$root_pass); //sets login info - we have to validate you before we can run api calls
    $xmlapi->set_http_client('curl'); //??? - same as linux client?  someone else might be able to clarify further
    $xmlapi->set_port(2086); //default WHM non-ssl port
    $xmlapi->set_debug(1); // i don't know if you need this
    
    print $xmlapi->adddns($domain,$ip);  //i believe what runs the call
    
    Additionally here is the documentation link for our API: http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice