Search Our Database
Introduction to the cPanel API
Introduction
The cPanel API is a comprehensive interface that allows developers, system administrators, and hosting providers to programmatically interact with cPanel and WHM services. It enables automation of administrative tasks such as creating email accounts, managing DNS records, provisioning domains, and performing system-level operations without manually accessing the graphical user interface.
cPanel offers three primary APIs, each designed for different purposes:
- UAPI (User API) – For cPanel-level functions like managing email accounts, databases, and files.
- WHM API 1 – For server-wide operations such as creating or suspending cPanel accounts, managing packages, and handling reseller permissions.
- cPanel API 2 (Legacy) – An older version that has been largely replaced by UAPI, though still supported in many cases.
These APIs are accessible via command-line utilities, HTTP/HTTPS requests (using API tokens or Basic Authentication), and programming libraries in languages like PHP, Perl, and Python. This flexibility allows for seamless integration with billing systems (like WHMCS), control panels, provisioning scripts, and custom dashboards.
The cPanel API is especially important in scenarios where large-scale automation is needed—such as hosting resellers managing hundreds of user accounts, or DevOps teams deploying services across multiple cPanel servers. It reduces manual overhead, increases consistency, and ensures that administrative operations are performed efficiently and programmatically.
Understanding the cPanel API involves learning how to authenticate securely, choose the appropriate API for a given task, interpret responses, and handle errors. This introductory article provides a high-level overview of the API types, access methods, use cases, and official documentation references to help users begin leveraging the full potential of cPanel’s API ecosystem.
Prerequisites
- A server with cPanel & WHM version 11.52 or later installed.
- Root or reseller access to WHM (for WHM API usage).
- A cPanel account with proper privileges (for UAPI usage).
- Familiarity with command-line tools like curl or programming languages like PHP or Python.
- Internet access to communicate with the server’s API endpoints.
- (Optional) API token created from WHM or cPanel for secure authentication.
Step-by-step Guide
Step 1: Understand the Three API Types
1. UAPI (User API)
Used by cPanel users to perform operations such as:
- Creating email accounts
- Managing cron jobs
- Editing DNS zones (if permitted)
Example endpoint:
/usr/bin/uapi --user=username Email add_pop email=user domain=example.com password=securepass quota=250
2. WHM API 1
Used by root or reseller users to manage server-level or multi-user tasks:
- Creating/suspending accounts
- Managing packages
- Modifying reseller privileges
curl -H'Authorization: WHM root:API_TOKEN' \ "https://hostname.example.com:2087/json-api/createacct?username=testuser&domain=test.com&plan=default"
3. cPanel API 2 (Legacy)
Older interface with functions similar to UAPI, still available for backward compatibility.
Step 2: Authenticate with API Tokens
API tokens provide secure, non-password-based authentication for API requests.
- Log in to WHM → Development → Manage API Tokens
- Click Create, give it a name, and assign appropriate permissions.
Use it in a header like:
-H 'Authorization: WHM root:API_TOKEN'
Alternatively, for cPanel users:
- Log in to cPanel → Security → Manage API Tokens
Step 3: Perform a Sample API Request
For example, to create a new cPanel account using WHM API:
curl -H 'Authorization: WHM root:API_TOKEN' \ "https://your-hostname:2087/json-api/createacct?username=demo&domain=demo.com&plan=default"
To create an email account using UAPI:
uapi --user=username Email add_pop email=user domain=example.com password=securepass quota=100
Step 4: Parse API Responses
All API responses are returned in JSON (for HTTP-based calls). A typical successful response includes:
{ "metadata": { "version": 1, "reason": "OK", "result": 1 }, "data": { "email": "user@example.com" } }
Step 5: Explore the Official API Documentation
- UAPI Docs: https://api.docs.cpanel.net/uapi/
- WHM API 1 Docs: https://api.docs.cpanel.net/whm/
- API Authentication Guide: https://api.docs.cpanel.net/auth/
Conclusion
The cPanel API ecosystem offers robust functionality for automating both user-level and server-wide operations. Understanding the differences between UAPI, WHM API 1, and the legacy cPanel API 2 is essential when choosing the right interface for a task. With secure authentication via API tokens and a consistent JSON response format, these APIs are well-suited for building custom integrations and automating hosting workflows.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.