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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED xmlapi addsubdomain gives error in cpanel.pl line 1825

Discussion in 'cPanel Developers' started by nickwuk, Jun 27, 2017.

  1. nickwuk

    nickwuk Member

    Joined:
    Jul 18, 2009
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    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?
     
    #1 nickwuk, Jun 27, 2017
    Last edited: Jun 27, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,659
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
  3. nickwuk

    nickwuk Member

    Joined:
    Jul 18, 2009
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    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);
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,659
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

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

Share This Page