How to Access a cPanel Account through WHM

jwhm

Member
Feb 22, 2021
11
0
1
United Kingdom
cPanel Access Level
Reseller Owner
I need to be able to add an email account to a cPanel account through WHM, is this possible?

I plan to build this into a interface where my clients can add email accounts without seeing cPanel.

I can't create a token for the cPanel account, as I have well over 300 clients.
 
Last edited by a moderator:

cPanelTJ

Product Owner
Staff member
Jan 29, 2019
84
39
93
Houston, TX
cPanel Access Level
Root Administrator
Twitter
With root access, you'd simply call the cPanel UAPI functions on behalf of the users. This concept is usually referred to as "masquerading".

It would look something like this over bash/CLI:
Code:
uapi --user=<username> Email add_pop email='user' password='123456luggage'
Here is the full documentation on the API function: Create email address · cPanel & WHM Developer Portal
 
  • Like
Reactions: cPRex

jwhm

Member
Feb 22, 2021
11
0
1
United Kingdom
cPanel Access Level
Reseller Owner
PHP:
$ch2 = curl_init( 'https://lima.example.io:2087/json-api/create_user_session?api.version=1&user=<CPANEL ACCOUNT>%40<CPANEL DOMAIN>&service=cpaneld' );

curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
    'Authorization: cpanel',
    '<username>: <WHM Token>'
));

curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, true );

$stack = curl_exec($ch2);

curl_close($ch2);
I have tried this, but it won't work any pointers?

I was going to do this

> Create a Session(from WHM token)
> Use session to add email, domains etc
 

jwhm

Member
Feb 22, 2021
11
0
1
United Kingdom
cPanel Access Level
Reseller Owner
Fixed.

I have managed to create a cpsess for a cPanel account through WHM API using a Token.

PHP:
/cpsess9617913732/json-api/cpanel?cpanel_jsonapi_user=<USERNAME>&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addpop&domain=<DOMAIN>&email=example&password=eXample!10!
However, upon using that cpsess to access Email Module, I keep getting 'Access Denied'.
 
Last edited: