How to activate CPANEL API so I can create e-mail accounts using the API?

Operating System & Version
CENTOS 7.8
cPanel & WHM Version
WHM v88.0.13 / cPanel 88.0 (build 13)

lopes80andre

Registered
Aug 19, 2020
1
0
1
Portugal
cPanel Access Level
Root Administrator
Hi all,

I have a WHM account/server that I've full access.

I need to create e-mail accounts using an API or something like that. I've read some documentation and activated the "cPanel & WHM API shell (for developers)" in WHM, but I've not been able to figure out how to setup cPanel so API calls are possible.

I've attached one image in the cPanel "Manage API Tokens" showing the disabled button that allow to create the token.

The objective is to use one of this libraries:

- vexxhost/python-cpanelapi
- oznu/pycpanel

My question is, what steps I'm not doing to generate a valid API Token?

I appreciate some kind of help.

Best Regards,cpanelAPI.png
 

cPanelTJ

Product Owner
Staff member
Jan 29, 2019
97
50
93
Houston, TX
cPanel Access Level
Root Administrator
Twitter
@lopes80andre ,

The APIs on your server should be active from the start. The API Shell is a tool that helps explore the functionality of the APIs, but it is not required in order to make API calls to your server.

If you are wanting to make these calls locally on the server (not from a remote location), you can easily do it over command line or with bash scripts. In this case, you wouldn't need an API token either.

If you need to make these calls from a remote location to the server, then you will need an API Token. The "Create" button is disabled in your screenshot because you have not given the API Token a name in the field at the top. This field is required and populating it will activate the "Create" button.

Additionally, neither of the libraries that you shared support our latest cPanel API called UAPI. cPanel API 1 is deprecated and slowly being removed now, so any integrations that use it will not continue to work for much longer.

Here is the UAPI call to add an email address under a cPanel account: https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email::add_pop

If you were to make this call over the command line as root, it would look something like:
Code:
uapi --user=$user Email add_pop email=user password=12345luggage quota=0 domain=example.com skip_update_db=1
Where $user is the name of the cPanel account where you want the add the email address. This method where the root user makes an API call on behalf of a cPanel user is known as masquerading. A root user can do this with any of the available UAPI calls for cPanel.

If you make the call as the cPanel user over command line, --user=$user can be left off.
 
  • Like
Reactions: cPanelLauren