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.

Nested subdomain Creation

Discussion in 'cPanel Developers' started by Robertfayez, Aug 3, 2014.

  1. Robertfayez

    Robertfayez Member

    Joined:
    Aug 3, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I need to create sub-subdomain; something like sub.subdomain.maindomain.com



    Code:
            $cpanelHost = "subdomain.maindomain.com";
            $xmlapi = new xmlapi($cpanelHost);
       	$xmlapi->password_auth($cpanelUsername,$cpanelPassword);
    	$xmlapi->set_debug(1);
    	$xmlapi->set_output('array');
    	$xmlapi->set_port($cpanelPort);
       
    	$addsub = $xmlapi->api2_query($cpanelUsername,"SubDomain","addsubdomain",array("rootdomain"=>$cpanelHost,"domain"=>"sub", "dir" => "/public_html/sub"));	
    
    Am getting the sub under maindomain.com, so the result is sub.maindomain.com instead of sub.subdomain.maindomain.com.

    Anyone knows how to make it?

    Thanks in advance
     
  2. Robertfayez

    Robertfayez Member

    Joined:
    Aug 3, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Anyone know how to create sub2.sub1.domain.com using XMLapi? where sub1 is an A record (a new account) under the main domain.
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Please ensure you follow the guidelines for this function:

    API2 Function - addsubdomain

    I tested with the following JSON-API call and it worked well:
    Code:
    /json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=addsubdomain&domain=test1.test2&rootdomain=cptesting.com
    Notice how "test1.test2" is used for the "domain" parameter without the root domain name.

    Thank you.
     
  4. Robertfayez

    Robertfayez Member

    Joined:
    Aug 3, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thank you Michael, It's clear now I should use

    Domain:test1.dev
    Rootdomain:maindomain.com

    and not

    Domain:test1
    Rootdomain:dev.maindomain.com

    Thanks a lot, But when I used it, I got this message:

    Code:
    Array
    (
        [apiversion] => 2
        [data] => Array
            (
                [reason] => The domain “dev.worksitesimple.com†does not exist.
                [result] => 0
            )
    
        [error] => The domain “dev.worksitesimple.com†does not exist.
        [event] => Array
            (
                [result] => 1
            )
    
        [func] => addsubdomain
        [module] => SubDomain
    )
    
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Could you post the code you are using for the creation? Note that you can enable the "API Shell" option in cPanel to make sure you are using the correct parameters:

    API Shell

    Thank you.
     
  6. Robertfayez

    Robertfayez Member

    Joined:
    Aug 3, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi Michael,

    Thank you for your help, I really appreciate it, here you go the code am using
    Code:
    <?php
    	include_once 'xmlapi.php';
    	$cpanelUsername = "rootusername";
    	$cpanelPassword = "rootpassword";
    	$cpanelHost = "maindomain.com";
    	$cpanelPort = 2087;
    	
    	$xmlapi = new xmlapi($cpanelHost);
       	$xmlapi->password_auth("".$cpanelUsername."","".$cpanelPassword."");
    	$xmlapi->set_debug(1);
    	$xmlapi->set_output('array');
    	$xmlapi->set_port($cpanelPort);
       
    	$addsub = $xmlapi->api2_query($cpanelUsername, "SubDomain", "addsubdomain",
                                         array(
                                                 "rootdomain"=>$cpanelHost,
                                                 "domain"=>"dev3.dev", 
                                                 "dir" => "/public_html/dev3"
                                          ));	
    	
    
            print_r($addsub);
    	
    	
    ?>
    
    Where I've already a new account called dev.maindomain.com, this created a DNS zone automatically.

    Thanks
    Robert
     
  7. Robertfayez

    Robertfayez Member

    Joined:
    Aug 3, 2014
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    It's working normally right now after updating the "domain" and $cpanelUsername variables.. I used the root username to authenticate, but the account user name to create the subdomain.

    Robert
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page