xmlapi addsubdomain gives error in cpanel.pl line 1825
I'm using the following code to add a sub domain:
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?
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?
-
Hello, Here's a closer example, using JSON instead of XML, that you may find helpful: JSON-API calls to make new subdomain, email, ftp, and database help Thank you. 0 -
@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);[/PHP] 0 -
Hello, I'm glad to see you were able to get it working. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
3 comments