cPanel/SubDomain
cPanel module

SubDomain

2 functions, invoked through the cpanel_uapi tool.

scope cpanel:uapi
Call any function with cpanel_uapi(service_id, module="SubDomain", function, params). Live availability depends on the cPanel features JetHost has enabled on your account — call list_cpanel_operations to see what is active.

addsubdomain GET#

Create subdomain

This function creates a subdomain.

Important:

When you disable the Web Server role, the system disables this function.

domainstringRequired
The subdomain name to create.
rootdomainstringRequired
The domain on which to create the new subdomain. The domain must already exist on the cPanel account.
canoffintegerOptional
Whether to use a canonical name (CNAME) in the Apache® configuration for self-referential URLs. 1 - Use the CNAME. 0 - Do not use the CNAME.
dirstringOptional
The subdomain's document root within the home directory, given as a valid directory path relative to the user's home directory. This value defaults to the user's home directory /public_html/ path. Note: If the Restrict document roots to public_html value is set to Off in WHM's Tweak Settings interface (WHM >> Home >> Server Configuration >> Tweak Settings), this parameter defaults to the /username/ path. For example, the username user's subdomain example would default to the /home/username/example path.
disallowdotintegerOptional
Whether to remove the dot (.) characters from the domain value. 1 - Remove dots from the domain. 0 - Do not remove dots from the domain.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

Payload varies by call.

changedocroot GET#

Change a subdomain or addon domain document root

This function changes the document root for a subdomain or addon domain that the calling cPanel user owns.

Important:

  • This function does not apply to the account's primary domain.

Use the WHM API set_primary_domain_docroot function to change the document root for a primary domain.

  • The target directory must already exist before you call this function.

The function does not create it.

  • This function does not move any files. You must ensure that the files

exist in the new path when you call this function.

  • Any parked domains (ServerAlias entries) on the affected domain will

inherit the new document root.

  • AutoSSL HTTP-01 renewals will fail if the new document root is empty

or missing at renewal time.

  • To revert a document root change, call this function again with the

original path.

When you disable the Web Server role, the system disables this function.

docrootstringRequired
The new document root as a path relative to the user's home directory. The target directory must already exist, and the path must begin with public_html/ if the Restrict document roots to public_html value is set to On in WHM's Tweak Settings interface (WHM >> Home >> Server Configuration >> Tweak Settings).
domainstringRequired
The full domain name of the subdomain or addon domain whose document root you want to change. The domain must belong to the calling cPanel user.