We have a new documentation site for cPanel & WHM! You can find our new documentation site at docs.cpanel.net.

We will continue to maintain our API documentation on this server.

Child pages
  • WHM API 1 Functions - create_subdomain
Skip to end of metadata
Go to start of metadata

Description

This function creates a subdomain.

Examples


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/create_subdomain?api.version=1&domain=subdomain.example.com&document_root=public_html/directory_name&use_canonical_name=0
 Command Line
whmapi1 create_subdomain domain=subdomain.example.com document_root=public_html/directory_name use_canonical_name=0


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 (JSON)
{
  "data": {
	"username": "example"
  },
  "metadata": {
    "version": 1,
    "reason": "OK",
    "result": "1",
    "command": "create_subdomain"
  }
}


Note:

Use WHM's API Shell interface (WHM >> Home >> Development >> API Shell) to directly test WHM API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
domainstring

Required

The subdomain name to create.

A valid subdomain name.

subdomain.example.com
document_rootstring

Required

The subdomain's document root within the home directory.

Note:

  • An invalid document root path will cause this function to fail.
  • 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), this parameter must begin with the public_html/ path. For more information, read the cpanel.config file documentation.

A valid directory path, relative to the user's home directory.

public_html/directory_name

use_canonical_name

Boolean

Whether to use a canonical name in the Apache® configuration for self-referential URLs.

This value defaults to 0.

  • 1 — Use the canonical name.
  • 0 — Do not use the canonical name.
0

Returns

ReturnTypeDescriptionPossible valuesExample
usernamestring

The cPanel account username.

Note:

This return only appears if the function succeeds.

A valid cPanel account username.

example