Using cPanel API tokens to automate your hosting
The cPanel API (UAPI) lets scripts and apps do the same things you do in cPanel, without logging in: create email accounts, manage databases and domains, start backups and more. To use it from outside your hosting account, you need an API token. API tokens are available on every Ruachost hosting plan.
Create an API token
Section titled “Create an API token”- Log in to cPanel and open Manage API Tokens under Security.
- Click Create.
- Enter a name that says what it’s for, for example
backup-scriptorn8n. Use letters, numbers, dashes and underscores only. - Under Expiration, choose a date. A token without an expiry date works until you delete it.
- Click Create.
- Copy the token now and store it somewhere safe, such as a password manager. cPanel shows it only once.
Make an API call
Section titled “Make an API call”Every call is an HTTPS request to your server on port 2083, with your cPanel username and token in the Authorization header:
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/MODULE/FUNCTION?PARAMETERS"Replace:
CPANEL_USERNAMEwith your cPanel username. See Finding your cPanel username.API_TOKENwith your token.SERVER_HOSTNAMEwith your server’s hostname, shown in cPanel under General Information (Server Name), or in your welcome email.
The response is JSON. "status": 1 means it worked; if not, errors explains why.
Examples
Section titled “Examples”List your domains:
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/DomainInfo/list_domains"List email accounts:
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/Email/list_pops"Create an email account (2048 MB quota):
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/Email/add_pop?email=sales&domain=example.com&password=A-Strong-Password-123"a=2048"List MySQL databases:
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/Mysql/list_databases"Create a full account backup in your home directory, and email you when it’s done:
curl -H "Authorization: cpanel CPANEL_USERNAME:API_TOKEN" \ "https://SERVER_HOSTNAME:2083/execute/Backup/fullbackup_to_homedir?email=you@example.com"The full list of modules and functions is in the cPanel UAPI documentation.
Running API calls on the server itself (no token needed)
Section titled “Running API calls on the server itself (no token needed)”Scripts that run on your hosting account, such as cron jobs or commands over SSH, can use the uapi command instead. It’s already logged in as you, so no token is needed:
uapi --output=jsonpretty Email list_popsFor example, this cron job creates a full backup every Sunday at 2am:
0 2 * * 0 /usr/bin/uapi Backup fullbackup_to_homedir email=you@example.com > /dev/null 2>&1Backups use disk space in your account, so download and delete old ones. Your account is also backed up automatically with JetBackup. See Restoring files, email and databases using JetBackup.
Using tokens with apps
Section titled “Using tokens with apps”Automation tools such as n8n, Zapier (Webhooks), Make or your own app can call the cPanel API. Use an HTTP request step with:
- URL:
https://SERVER_HOSTNAME:2083/execute/MODULE/FUNCTION - Header:
Authorization=cpanel CPANEL_USERNAME:API_TOKEN
Store the token in the tool’s credentials or secrets store, not directly in the workflow.
Manage and revoke tokens
Section titled “Manage and revoke tokens”In Manage API Tokens, you can see each token’s name, creation date and expiry. Click a token to Revoke it. Revoked tokens stop working immediately. If you think a token has leaked, revoke it straight away and create a new one.
Troubleshooting
Section titled “Troubleshooting”- “Access denied” or 401: check the username and token, and that the header starts with
cpanelfollowed by a space. - Connection times out: check you’re using port 2083 and the server hostname. Many failed attempts can block your IP address. See My IP address is blocked.
- “The function … does not exist”: check the spelling and capital letters of the module and function names.
Related articles
Section titled “Related articles”Was this page helpful?
Thanks for your feedback.