cPanel recently introduced an application programming interface (API) tokens interface with cPanel 80.
The cPanel & WHM API functions allow you to create, modify, and remove information on your server (among other things) without the need to log in to the cPanel interface.
For example, cPanel users can issue these API tokens to a third-party developer or use that token to check disk usage.
You could also issue an API token to a reseller who could use that token to check disk usage.
The server recognizes API tokens and allows other users to run API functions with the account's data.
Please note that this feature & functionality is experimental and thus may change in future versions.
To use a cPanel API token, first, you must create a cPanel API token via cPanel's Manage API Tokens interface found at cPanel >> Home >> Security >> Manage API Tokens.
Then, use the token to run API functions on the server.
Column | Description |
Token Name | The API token's name. |
Manage |
Click Manage to open a new interface where you can perform the following actions:
|
Created | The date and time that you created the API token. |
To start:
- Navigate to cPanel's Manage API Tokens interface at Security >> Manage API Tokens.
- Click Create. The Create API Token interface will appear.
- Enter a name in the API Token Name text box.
- An API token name can only contain up to 50 characters.
- You can only enter letters (a – z) and (A – Z), numbers (0 – 9), dashes ( - ), and underscores ( _ ).
- You must enter a name that does not already exist on the account.
- Click Create. A new interface will appear. To copy the API token, click Copy. You must enter this token each time that you call an API function, similar to a password. Please note that you cannot access the token after you navigate away from the interface. If you forget or misplace this token, you must revoke the token and then create a new one.
- Click Yes, I Saved My Token.
- To create a new token, select the Create another token after I click Yes, I saved my token checkbox.
- To return to the List API Tokens interface, deselect the Create another token after I click Yes, I saved my token checkbox.
How To Run API functions With The Token
Please remember that the API tokens run UAPI functions and cPanel API 2 functions, not cPanel API 1 functions.
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://domain_name.com:2083/execute/Module/function?parameter=value'
This example uses the following format:
Item | Description | Examples |
username | The cPanel account's username. | user |
APITOKEN | the API token | JHK4uCc7gUDZTQcX4EiKNaRCCEYKD5154 |
domain_name.com | your cPanel server domain | domain_name.com or IP address |
Module | the API module | |
function | the API function's name | add_pop |
parameter | the function's input parameters. | |
value | the value to assign to the input parameter | 7s57b4i7smartphone |
For example, your command may resemble the following example:
curl -H'Authorization: cpanel username:JHK4uCc7gUDZTQcX4EiKNaRCCEYKD5154' 'https://example.com:2083/execute/Email/add_pop?email=newuser&password=7s57b4i7smartphone'
If you have created additional API tokens, you can display these API tokens per page by clicking the gear icon and then select a number.
To revoke multiple tokens:
- Select the checkboxes for each token to revoke. Select the checkbox at the top of the table to select every token.
- Click Revoke. A confirmation message will appear.
- Click Revoke Selected API Tokens.
How To Manage An API Token
To manage an API token, locate the token in the API Tokens table and then click Manage.
The Manage API Token interface will appear.
To assign a new name for the token, enter a new name in the New API Token Name text box.
Then click Update.
To revoke an API token:
- Click Revoke. A confirmation message will appear.
- Click Yes, Revoke the Token to revoke the token.