You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • cPanel API 1 Functions - SubDomain::addsubdomain
Skip to end of metadata
Go to start of metadata

Description

This function adds a subdomain to a domain.

Warning:

cPanel API 1 is deprecated. Do not use this function. Instead, we strongly recommend that you use the following newer functions:

Examples 


 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
$add_domain = $cpanel->api1('SubDomain','addsubdomain', array('subdomain','example.com','0','1','public_html/subdomain') ); // Call the function.


Note:

For more information, read our Guide to the LiveAPI System.

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
my $add_domain = $cpliveapi->api1('SubDomain','addsubdomain', ['subdomain','example.com','0','1','public_html/subdomain'] ); # Call the function.


Note:

For more information, read our Guide to the LiveAPI System.


 cPanel Tag System (deprecated)


Warning:

In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We provide this example to help developers move from the old cPanel tag system to our LiveAPI system. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs.

<cpanel Module="SubDomain::addsubdomain( $FORM('domain','rootdomain','canoff','disallowdot','dir') )">
 Command Line
cpapi1 --user=username SubDomain addsubdomain subdomain example.com 0 1 public_html/subdomain


Notes:

  • Unless otherwise noted, you must URI-encode values.
  • For more information and additional output options, read our Guide to WHM API 1 documentation or run the whmapi1 --help command.
  • If you run CloudLinux™, you must use the full path of the whmapi1 command:

    /usr/local/cpanel/bin/whmapi1

 Output (plaintext)
The subdomain "subdomain.example.com" has been added.

   

Parameters

ParameterTypeDescriptionPossible valuesExample
domain

string

Required

The subdomain to add.

A valid subdomain string.subdomain
rootdomainstring

Required

The domain name.

A valid domain name.example.com
canoffBoolean

Whether to use a canonical name (CNAME) for the subdomain.

This parameter defaults to 0.

  • 1 — Don't use a CNAME.
  • 0 — Use a CNAME.
0
disallowdotBoolean

Whether to strip the dots from the domain parameter.

This parameter defaults to 0.

  • 1 — Strip all dots.
  • 0 — Strip only the trailing dot.
1
dirstring

The path to the subdomain's document root, relative to the account's home directory.

This parameter defaults to public_html.

A valid relative path.
public_html/subdomain

Returns

This function returns a confirmation message.