Utilize cPanel APIs To Manage Task

By Anurag Singh

Updated on Jun 09, 2025

Utilize cPanel APIs To Manage Task

In this tutorial, we'll learn how to utilize cPanel APIs to manage task.

As a web hosting provider, streamlining repetitive server administration tasks can save you time, reduce human error, and improve customer service. That’s where cPanel’s robust APIs come in. Whether you’re managing account creation, SSL installations, DNS zones, or email setups, cPanel APIs allow you to automate it all efficiently.

We’ll walk you through how to use cPanel's UAPI and WHM API 1 to automate hosting operations. We’ll cover practical examples that web hosts commonly need. You’ll also learn how to authenticate, make API calls using curl or Python, and handle responses.

Prerequisites

Before you start using the API, ensure the following:

What Are cPanel APIs?

cPanel offers two main API types:

UAPI (User API): Interacts with features available within individual cPanel accounts.

Example: Create an email account, install SSL, or manage files.

WHM API 1 (WebHost Manager API): Used by server admins and resellers to manage accounts and server-wide settings.

Example: Create a cPanel account, suspend a user, or configure quotas.

These APIs use HTTP/S requests and return responses in JSON, making them easy to work with using tools like curl, Python, Node.js, or PHP.

Authentication Methods

You can authenticate cPanel/WHM API requests in multiple ways:

Root or Reseller API Tokens (Preferred):

Secure and recommended for automation.

How to Create an API Token in WHM:

  • Login to WHM as root.
  • Go to: Development → Manage API Tokens
  • Click Generate Token, set a name and privileges.
  • Copy the token (you won’t see it again).

Basic Authentication:

Use username and password (less secure, not recommended for automation).

Basic WHM API Request with curl

To create a new cPanel account:

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/createacct?username=newuser&domain=example.com&plan=Basic"
  • cpanel root:YOUR_API_TOKEN is your authentication.
  • Replace YOUR_SERVER, username, domain, and plan accordingly.

Response:

  • You’ll receive a JSON object with success or error details.
  • Common Automated Hosting Tasks Using cPanel APIs

1. Create a cPanel Account (WHM API 1)

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/createacct?username=client01&domain=clientdomain.com&password=StrongP@ss123&plan=Starter"

You can also pass additional parameters like contactemail, maxsql, maxpop, etc.

2. List All Accounts

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/listaccts"

Helpful for account monitoring scripts.

3. Create an Email Account (UAPI)

To create an email on a cPanel account (use UAPI via cPanel port 2083):

curl -s -k -H 'Authorization: cpanel username:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2083/execute/Email/add_pop?email=support&domain=clientdomain.com&password=EmailP@ss123&quota=1024"

4. Install Free SSL (AutoSSL)

curl -s -k -H 'Authorization: cpanel username:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2083/execute/SSL/install_autossl_provider"

Or trigger AutoSSL scan:

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/start_autossl_check"

5. Manage DNS Zones

To add a new DNS A record:

curl -s -k -H 'Authorization: cpanel username:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2083/execute/DNS/add_zone_record?domain=example.com&name=sub.example.com&type=A&address=192.0.2.1"

6. Suspend or Unsuspend a cPanel Account

Suspend:

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/suspendacct?user=client01&reason=Overdue"

Unsuspend:

curl -s -k -H 'Authorization: cpanel root:YOUR_API_TOKEN' \
"https://YOUR_SERVER:2087/json-api/unsuspendacct?user=client01"

Using Python for cPanel API Automation

Here’s a sample Python snippet to create an account:

import requests

api_token = "YOUR_API_TOKEN"
host = "https://YOUR_SERVER:2087"
user = "root"

headers = {
    "Authorization": f"cpanel {user}:{api_token}"
}

params = {
    "username": "client02",
    "domain": "clientexample.com",
    "password": "Str0ngP@ssword!",
    "plan": "Basic"
}

response = requests.get(f"{host}/json-api/createacct", headers=headers, params=params, verify=False)

print(response.json())

This is ideal for integrating into dashboards or CRON-based scripts.

Security Best Practices

  • Always use API tokens instead of usernames and passwords.
  • Limit token privileges based on the intended automation use.
  • Use https:// and verify SSL certificates in production.
  • Rotate tokens periodically.
  • Log all automation actions for traceability.

Real-Life Use Cases for Hosting Providers

Client Onboarding Automation:
As soon as a client signs up, trigger account creation and email setup automatically.

Monitoring and Reporting:
Automatically fetch account data for monthly summaries or usage-based billing.

Bulk Management:
Update DNS records, suspend/unsuspend accounts, or reset passwords in bulk.

Integrations with Billing Systems:
Connect APIs with WHMCS, HostBill, or custom portals for seamless provisioning.

Conclusion

The cPanel UAPI and WHM API 1 are powerful tools for automating your hosting business. Whether you're managing ten clients or ten thousand, these APIs let you scale operations without scaling your staff. By integrating them into your systems, you not only reduce manual errors but also provide faster, more reliable services to your customers.

If you're not using these APIs yet, start by identifying the most repetitive admin task in your workflow — and script it using the examples above.