Hosting through the API: subdomains, databases, cron jobs, SSL, PHP options and FTP

cPanel & WHM·· 23 views· 4 min read

The short answer: the API reads your account's services and manages active hosting: plan usage, subdomains, addon domains, redirects, databases, cron jobs, SSL, PHP options, backups and FTP. Everything runs in that service's account. You read with hosting:read and change with hosting:write.

Finding the service

GET /v1/services returns every service in the account, most recent first, in pages (filter ?status=active). GET /v1/services/{id} shows the product, address, status, cycle, amount and next due date, but never passwords. While a service is unpaid, domain and username may be null. The id is what you use in every operation below.

What you can manage

Area Operations Notes
Usage GET /v1/services/{id}/usage Disk, traffic and plan resources.
Subdomains GET, POST, DELETE .../subdomains Deleting needs the name in confirm.
Addon domains GET, POST, DELETE .../addon-domains Deleting needs the name in confirm.
Redirects GET, POST, DELETE .../redirects Deleted by id alone.
Databases and users .../databases, .../database-users The account prefix is added automatically on creation.
Cron jobs GET, POST, DELETE .../cron Creating needs hosting:code.
SSL GET .../ssl, POST .../ssl/autossl Request the free ones, once every 15 minutes.
PHP GET .../php, GET and PUT .../php/options Reads the version; changes options such as memory_limit.
Backups GET and POST .../backups One full backup on request, once a day.
FTP .../ftp-accounts Creating and changing passwords needs hosting:code.

Example: a subdomain for the blog

curl https://api.mozout.com/v1/services/123/subdomains -X POST \
-H "Authorization: Bearer $RLX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"root_domain": "yourcompany.com", "name": "blog", "directory": "public_html/blog"}'

Folders are always relative to the account folder, such as public_html/blog; .. and system folders are not accepted. An addon domain, or the root of a subdomain, must be active in your account (registered with us, or belonging to an active hosting plan); otherwise the answer is 409 with domain_not_owned. A domain registered elsewhere is added in cPanel.

Cron jobs without free-form commands

To create a job you give php_script (a PHP file in the account) or url (a public address to call), and the timing in schedule. The shortest interval is 5 minutes and each account can have up to 20 jobs. The address must use a domain name that resolves to public addresses, never an IP or an internal name. For other commands, use cPanel.

{ "schedule": "*/15 * * * *", "php_script": "public_html/cron.php" }

The cPanel login link (POST /v1/services/{id}/cpanel-login, with hosting:login) works only once and gives full access to the panel: use it straight away and never store it in logs. For the same reason, a cron job's command is only filled in with hosting:code; without it, command_hidden comes back true.

When it answers 409 or 502

Only on active hosting, on a supported server. Otherwise, 409 with not_hosting, service_not_active, server_not_supported or service_not_ready; a service from another account gives 404. If the server does not answer as expected, you get a 502. Changes are limited to 20 per minute, per hosting account, and panel logins to 5 per minute.

What is still done in cPanel or My MozOut: changing the PHP version, files, Git, Node.js and restoring backups. Database passwords are 12 to 128 characters, with at least 3 kinds among lowercase, uppercase, digits and symbols, and never come back in answers. To give other tools access without the API, there are also cPanel API tokens.

Want to automate your hosting? See the API page and start with a Sandbox key that only has hosting:read.

See the API page

SEE ALSO

Hosting e-mail through the API: mailboxes, passwords, quotas, forwarders and the default address

DNS through the API: adding, changing and deleting records, and restoring a zone backup

Sensitive API permissions and the spending limit: paying, buying, reinstalling, cPanel access

Idempotency-Key in our API: repeating a purchase, payment or ticket without doing it twice

API request limits: per key, per account and per task, the headers and what to do after a 429

cPanel API tokens: automating without handing over your password

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.