SOLVED xmlapi addsubdomain gives error in cpanel.pl line 1825

nickwuk

Active Member
Jul 18, 2009
28
2
53
I'm using the following code to add a sub domain:

Code:
include 'xmlapi.php';

$cpanel_host = 'mydomain.uk';
$cpanel_user = 'someuser';
$subdomain = 'mysubdomain';
$cpanel_pass = 'mypass';
$dir = 'public_html/'.$subdomain;

$xmlapi = new xmlapi($cpanel_host);
$xmlapi->password_auth($cpanel_user, $cpanel_pass);
$xmlapi->set_http_client('curl');
$xmlapi->set_port(2083);
$xmlapi->set_output('json');
$xmlapi->set_debug(1);

$opts = array($subdomain,$cpanel_host,$dir,'1');

print $xmlapi->api1_query($cpanel_user, "Subdomain", "addsubdomain", $opts);
And the error I get is: Can't use an undefined value as a subroutine reference at cpanel.pl line 1825

As another test, and using the same authorisation code, the function addpop to add a new mailbox works fine.

Cpanel version 62.0(build 7), Php 5.6.30, Perl 5.10.1, theme 'paper_lantern'.

Any ideas please?
 
Last edited:

nickwuk

Active Member
Jul 18, 2009
28
2
53
@cPanelMichael thanks for the link. To start with I couldn't see much difference in the code since the variable $json_client was the same as my $xmlapi ie an both instance of class xmlapi. Looking closer I found that I needed to change the module title from 'Subdomain' to 'SubDomain' with an uppercase 'D', use function api2_query instead of api1_query, and restructure my $opts array to include keys and then it worked.

PHP:
include 'xmlapi.php';

$cpanel_host = 'mydomain.uk';
$cpanel_user = 'someuser';
$subdomain = 'mysubdomain';
$cpanel_pass = 'mypass';
$dir = 'public_html/'.$subdomain;

$xmlapi = new xmlapi($cpanel_host);
$xmlapi->password_auth($cpanel_user, $cpanel_pass);
$xmlapi->set_http_client('curl');
$xmlapi->set_port(2083);
$xmlapi->set_output('json');
$xmlapi->set_debug(1);

$opts = array('domain'    => $subdomain,
              'rootdomain'=> $cpanel_host,
              'dir'        => $dir,
              'disallowdot'=> '1');

print $xmlapi->api2_query($cpanel_user, "SubDomain", "addsubdomain", $opts);
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello,

I'm glad to see you were able to get it working. Thank you for updating us with the outcome.