David Conner
David Conner

Reputation: 67

How to create an addon domain using xmlapi-php?

I am trying to create an addon domain using xmlapi-php. I have a shared hosting account.

This sample code is from github

<?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);            
?>

I am having trouble getting this code to work to create an addon domain. How can it be done?

Upvotes: 2

Views: 2492

Answers (1)

David Conner
David Conner

Reputation: 67

Well I've figured it out to the best of my ability and here is the solution for all the lost souls out there:

Authentication

You need run the following code at least once for authentication and xml api wrapper:

// AUTHENTICATION -------------------------

  include("xmlapi.php");    

  $host = "Host ip address or Site.com";
  $my_user = "Your cPanel user ID";
  $my_pass = "Your cPanel password";

  $xmlapi = new xmlapi($host);
  $xmlapi->set_port(2083);
  $xmlapi->password_auth($my_user, $my_pass);
  $xmlapi->set_output('json');
  $xmlapi->set_debug(1);

Now you can start using the functions provided in the xmlapi.php but you are not limited to them.

Email Creation Example

// Calling on the function "addpop" "email_user@email_domain" ------------------------- 

  $email_user = "apitest";
  $email_password = "adfm90f";
  $email_domain = "somesite.com";
  $email_query = '10';
  $email_quota = '600';

  //$result will be set equal to the JSON output returned by the call
  //api1_query is the function
  //in the array is where you pass the required parameters

  $result = $xmlapi->api1_query($my_user, "Email", "addpop", 
  array($email_user, $email_password, $email_quota, $email_domain));

Displaying the results

 $result = json_decode($result, true); //Decoding the JSON results to PHP
 print_r($result); //Printing the array onto the page

 //example of displaying a particular array key, in this example its "result"

 echo $result['data']['result'];

Upvotes: 1

Related Questions