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.

Creating a Wild Card Subdomain with the API

Discussion in 'cPanel Developers' started by warren77, Mar 16, 2011.

  1. warren77

    warren77 Registered

    Joined:
    Mar 16, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I am using the CPanel API. I can create a subdomain fine. When I attempt to use the Wild Card character * for the subdomain name, it tells me that my subdomain is empty ''.

    >> [result] => Error from domain wrapper: The subdomain '' is not valid.

    how do I tell the API to use the * just like I would if I was logged into the CPanel?

    Thanks
     
  2. warren77

    warren77 Registered

    Joined:
    Mar 16, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    UPDATE


    If I try to name the subdomain

    *.test

    it gets set as

    test

    OR, if I try

    88*.test

    it gets set as

    88.test

    This leads me to believe that the * is being stripped before it can be acted on. I do have Conical set to 1.
     
  3. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,460
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Since this is a development related topic, I moved the thread to the Developer Discussion forum.

    When you say you are using the cPanel API, which API do you mean? API1, API2, xml-api? Also how are you communicating with the API?

    Could you provide a code snippet that demonstrates how you are performing your task?

    Finally which version of cPanel & WHM are you testing against?
     
  4. warren77

    warren77 Registered

    Joined:
    Mar 16, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I tried both API1 and API2. I am using PHP. I am obviously making the correct call, connecting, and providing the correct credentials, because if I use a word instead of the wild card, it correctly creates the subdomain.

    Here is the code, I replaced my domain with a place holder, otherwise it is exact. I only tried API1 or API2 at a single time, not both at the same time.


    Code:
    include("api/xmlapi.php");
    
    $domain = "*";
    $rootdomain = 'domain-name-here.COM'; 
    $usecanonicalname = 1; // 1 to use wildcard
    $disallowdot = 0; 
    $dir = 'public_html/';
    
    $arraySubDomain = array( $domain, $rootdomain, $usecanonicalname, $disallowdot, $dir ) ;
    $arraySubDomain2 = array( $dir,$disallowdot, $domain, $rootdomain   ) ;
    
    $subDomain = $xmlapi->api1_query($cpuser, "SubDomain", "addsubdomain", $arraySubDomain); 
    
    $subDomain2 = $xmlapi->api2_query($cpuser, "SubDomain", "addsubdomain", $arraySubDomain2); 
    
    cPanel Version 11.28.86
    WHM 11.28.86
     
  5. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi warren77,

    First thing I notice is in your API2 call, the argument array "$arraySubDomain2" is not an associate array. API2 uses key/value name pairings as opposed to API1 which takes it's parameters as ordered arguments. In practical terms, that means when you use the XML-API PHP client class you should pass an associate array to api2_query() and an ordinal array to api1_query().

    If an API2 query with an ordinal argument array works, it's purely coincidental. Per chance, I've seen it work for other calls too, but to be certain, I'll make that an associate array:
    PHP:
    $arraySubDomain2 = array( 
                        
    'dir'          => $dir,
                        
    'disallowdot'  => $disallowdot,
                        
    'domain'       => $domain,
                        
    'rootdomain'   => $rootdomain
                        
    );
    please verify that this does or does not make a difference in the result of your wildcard domain request.

    Best Regards,
    -DavidN
     
  6. warren77

    warren77 Registered

    Joined:
    Mar 16, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Thank you, that did the trick.
     
  7. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Great!

    Glad I could help,
    -DavidN
     
Loading...

Share This Page