Creating a Wild Card Subdomain with the API

warren77

Registered
Mar 16, 2011
4
0
51
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
 

warren77

Registered
Mar 16, 2011
4
0
51
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.
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,607
80
458
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?
 

warren77

Registered
Mar 16, 2011
4
0
51
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
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
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