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

daveconners

Registered
Nov 6, 2013
1
0
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);

?>
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
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/