How to Use cPanel API Tokens
Last modified: February 21, 2024
Overview
cPanel users can issue application programming interface (API) tokens that allow you to view and change account data without the need to log in to the cPanel interface. The server recognizes these API tokens and allows other users to run API functions with the account’s data. For example, you could issue an API token to a third-party developer. That third-party developer could use that token to check disk usage.
- API tokens run UAPI functions and cPanel API 2 functions, not cPanel API 1 functions.
- To learn more about using API functions, read our Quickstart Development Guide documentation.
- If you do not see this feature, your system administrator has disabled it. Contact them and ask them to enable this feature in WHM’s Feature Manager interface (WHM » Home » Package » Feature Manager).
How to use a cPanel API token
To use a cPanel API token, first create a cPanel API token in cPanel’s Manage API Tokens interface (cPanel » Home » Security » Manage API Tokens). Then, use the token to run API functions on the server.
Create an API token
You can use one of the following methods to create an API token:
-
Use cPanel’s Manage API Tokens interface (cPanel » Home » Security » Manage API Tokens).
-
Use the UAPI
Tokens::create_full_access
function.
- When an API token expires, the system does not remove it. You must manually delete an API token.
- You can remove an API token with cPanel’s Manage API Tokens interface (cPanel » Home » Security » Manage API Tokens) or the UAPI
Tokens::revoke
function.
Run API functions with the token
You must use the API token that you created in cPanel.
To call a UAPI
or cPanel API 2
function with an API token, run the following command from the command line:
curl -H'Authorization: cpanel username:APITOKEN' 'https://example.com:2083/execute/Module/function?parameter=value'
This example uses the following format:
Item | Description | Example |
---|---|---|
username |
The cPanel account’s username. | username |
APITOKEN |
The API token. | U7HMR63FGY292DQZ4H5BFH16JLYMO01M |
example.com |
Your cPanel server’s domain. | example.com
Note:
Alternatively, you can enter your server’s IP address.
|
Module |
The API module name. | Email |
function |
The API function’s name. | add_pop |
parameter |
The function’s input parameters. | email |
value |
The value to assign to the input parameter. | 12345luggage |
For example, your command may resemble the following example:
curl -H'Authorization: cpanel username:U7HMR63FHY282DQZ4H5BIH16JLYSO01M' 'https://example.com:2083/execute/Email/add_pop?email=newuser&password=12345luggage'