Accessing cPanel API2 functions via WHM API

hlc

Member
Feb 10, 2015
7
0
1
cPanel Access Level
Root Administrator
Greets,

I successfully access cPanel API 2 functions using Perl via https://127.0.0.1:2082/xml-api/cpanel using a normal account username/password (eg, addpop etc).

I successfully access WHM API functions using Perl via https://127.0.0.1:2087/xml-api using the root username/password (eg, listaccts etc).

However, I want to access cPanel API 2 functions via WHM for all accounts hosted on the server (using the root username/password, since I don't have the user's cPanel account password), as per https://documentation.cpanel.net/display/SDK/cPanel+API+2+-+Calls+from+the+WHM+API :

Code:
https://127.0.0.1:2087/xml-api/cpanel?cpanel_xmlapi_user=root&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=listpops
But that fails with a 500/internal server error:

Code:
Could not setuid to root at /usr/local/cpanel/Whostmgr/XMLUI/cPanel.pm line 82.
cpsrvd/11.48.0.9 Server at 127.0.0.1
...and here we are :)

I'd appreciate any pointers - even if it means I'm doing something stupid. Is what I'm trying possible? I read somewhere that I can access all API services using the root/pw pair, but perhaps I'm mistaken.

Thanks
Henry
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
You should be able to access all cPanel API's via the 'cpanel' call with WHM API. That said, the user 'root' is probably not a cPanel user on your box. Try it out with one of the users with a valid cPanel account and let me know if you still have this problem.
 

hlc

Member
Feb 10, 2015
7
0
1
cPanel Access Level
Root Administrator
Thanks for the reply Andrew -

Using a normal cPanel account user login works, but that requires the password for that user.

I need access to the cPanel functions for ALL accounts using a single login (ie, root access). ie, the same way I can login to WHM API and create accounts, etc. I need that functionality for the cPanel API.
 

hlc

Member
Feb 10, 2015
7
0
1
cPanel Access Level
Root Administrator
Put another way, is it possible to access the Cpanel API via WHM using a non-cpanel username (eg, root, as I do with normal WHM API calls) to perform typical cPanel related actions (eg, creating an email, listing emails, etc)?
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
Try the call exactly as you had it before, just swap cpanel_xmlapi_user=root to cpanel_xmlapi_user=someuser.

You will still be authenticated as root but this just lets the API know to perform the action against that user. cPanel API's by design expect to know the username based on who makes the call, if you are calling it as root the API doesn't know what user to perform the action against. If you have any kind of password prompt you can also use the root or reseller password in place of the users but I don't think that should happen.
 

hlc

Member
Feb 10, 2015
7
0
1
cPanel Access Level
Root Administrator
[RESOLVED] Re: Accessing cPanel API2 functions via WHM API

Try the call exactly as you had it before, just swap cpanel_xmlapi_user=root to cpanel_xmlapi_user=someuser.

You will still be authenticated as root but this just lets the API know to perform the action against that user. cPanel API's by design expect to know the username based on who makes the call, if you are calling it as root the API doesn't know what user to perform the action against. If you have any kind of password prompt you can also use the root or reseller password in place of the users but I don't think that should happen.
Thanks for the assistance, that's working. In the authentication I need to use root:password (consistently), and cpanel_xmlapi_user=someuser (and no password specified).