AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
WHM API and cPanel API 1/2/UAPI are separate and not callable from each other by design currently; What API call are you trying to make or task are you trying to accomplish?
 

phoenixweb

Well-Known Member
Jun 3, 2004
70
0
156
cPanel Access Level
DataCenter Provider
WHM API can call every api1/api2 methods calling "cpanel" module.
I can do everything with WHM API logged as "root".

However api1/api2 are obsolete and they'll be replaced by UAPI (cPanel documentation warn to use UAPI instead API1/API2).
I think this is the way.

At the moment I have to:
- call an api2 method to add forward
- call an api1 method to del forward (which also appear to answer always 'result=1' even when i send wrong inputs).

API1 & API2 methods are just old and odd.
I see that uAPI have finally a standard format for vars, functions and outputs.
It seems just simple and clear.

However UAPI is completly useless for WHM integration if it's not callable by WHMapi
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
Oh good catch, I had forgotten about the cpanel module. Unfortunately I don't have a good solution to utilize cPanel UAPI directly besides calling it directly.

That said, I believe you can use a combination of the single sign on session to generate a user session key and then call the UAPI call with that key.
 

phoenixweb

Well-Known Member
Jun 3, 2004
70
0
156
cPanel Access Level
DataCenter Provider
I need to setup a single sign in order to execute every call to UAPI?
This will slow down the performance of the scripts and useless add extra requests to the server.

Then i'll continue to use API1/API2 calls instead of UAPI.
This is bad, that function are obsolete and would be good have a internal call without use 2 signing request at time (1 for root & 1 for user).
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
Actually after some testing internally it might be a bug. UAPI is technically API version 3, and as such you can pass in this and it actually makes an attempt to make the correct call. Unfortunately since this system was written before UAPI it doesn't know that it should be passing the parameters as a hash instead of an array. I opened an internal case 127073 and hopefully will have the fix in 11.48.
 

Alex Moleiro

Registered
Mar 11, 2015
2
0
1
Barcelona
cPanel Access Level
DataCenter Provider
I am trying to call UAPI from xmlapi_query as I understood from:
https://documentation.cpanel.net/display/SDK/UAPI+-+Calls+from+the+WHM+API

Then I call:
Code:
$this->object->xmlapi_query("ModSecurity", array("cpanel_xmlapi_version"=>"3",
                                                                           "api.version"=>"3",
                                                                       "cpanel_jsonapi_user"=>"dominable", 
                                                                        "cpanel_jsonapi_module"=>"ModSecurity", 
                                                                      "cpanel_jsonapi_func"=>"list_domains",
                                                                  "cpanel_jsonapi_apiversion"=>"3"
  ));
And the debug:

Code:
.URL: /https://s1.domain.com:2087/xml-api/ModSecurity
DATA: api.version=3&cpanel_jsonapi_user=domain&cpanel_jsonapi_module=ModSecurity&cpanel_jsonapi_func=list_domains&cpanel_jsonapi_apiversion=3
Authentication Header: Authorization: Basic **I manually changed it**
I received the response:
Code:
SimpleXMLElement Object
(
  [metadata] => SimpleXMLElement Object
  (
  [version] => 3
  [reason] => Unknown app requested for this version (3) of the api.
  [result] => 0
  [command] => ModSecurity
  )

)
I have changed losts of things, tried lots of combinations but nothing worked properly.

I need to disable mod_security sometimes to let my customers install applications that mod_security detects as false positive.

Thank you in advance
 
Last edited by a moderator:

DavidN.

Active Member
Mar 19, 2013
42
3
83
cPanel Access Level
DataCenter Provider
Hi Alex,

As far as I can tell, support for this doesn't exist yet, as of cPanel 11.48. The best suggestion I can offer is to create one user session, then re-use it for that user for subsequent API calls. Sessions expire 15 minutes after their most recent use.

David Nielson
Integration Developer, cPanel
 

Alex Moleiro

Registered
Mar 11, 2015
2
0
1
Barcelona
cPanel Access Level
DataCenter Provider
Hi David:

Thank you for your answer but
could you please point me out which api commands should I use to "create user session and then re-use it". I may imagine or find them but it takes me tons of hours because the documentation is a bit messy.

Thank you cPanel people for your extraordinary products.

Alex
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
You are using the "xmlapi" call but passing "cpanel_jsonapi" arguments. The API unfortunately does not know how to parse this properly. If you want XML, use "xmlapi" and "cpanel_xmlapi" accordingly, or "jsonapi" and "cpanel_jsonapi".


Here is a url I've tested on my development box that will call ModSecurity::list_domains for the user named "reseller" and return a json data structure.

Code:
/json-api/cpanel?api.version=1&cpanel_jsonapi_module=ModSecurity&cpanel_jsonapi_func=list_domains&cpanel_jsonapi_user=reseller&cpanel_jsonapi_apiversion=3

Same call with xml-api that returns an xml data structure
Code:
/xml-api/cpanel?api.version=1&cpanel_xmlapi_module=ModSecurity&cpanel_xmlapi_func=list_domains&cpanel_xmlapi_user=reseller&cpanel_xmlapi_apiversion=3

Your example provided cleaned up to what 'should' work (not tested)
Code:
$this->object->xmlapi_query("ModSecurity", array("api.version"=>"1",
                                                    "cpanel_xmlapi_user"=>"dominable",
                                                    "cpanel_xmlapi_module"=>"ModSecurity",
                                                    "cpanel_xmlapi_func"=>"list_domains",
                                                    "cpanel_xmlapi_apiversion"=>"3"
  ));
Note: Support for this does exist in 11.48.
 
Last edited:

DavidN.

Active Member
Mar 19, 2013
42
3
83
cPanel Access Level
DataCenter Provider
Mister Hodge is correct; support for UAPI (as "API version 3") is in 11.48. I don't know what I was doing wrong before, when I couldn't get it to work, but it's working for me now.

As of cPanel & WHM 11.48, it's no longer necessary to create user sessions just to make API calls on behalf of a user.
 

kjg

Well-Known Member
Mar 2, 2004
160
3
168
Yes, I know this is an old thread, but since I found it and it helped me after realising there were som errors in the code, I thought I'd put the working version out there if anyone else is looking for a solution to this.

It works fine calling cpanel UAPI via xmlapi class from 11.48

The example cPAndrewHodge gave had only a minor error that made it not work. (ModSecurity instead of cpanel as function).
This will work:

Code:
$this->object->xmlapi_query("cpanel", array("api.version"=>"1",
                                          "cpanel_xmlapi_user"=>"dominable",
                                          "cpanel_xmlapi_module"=>"ModSecurity",
                                          "cpanel_xmlapi_func"=>"list_domains",
                                          "cpanel_xmlapi_apiversion"=>"3"
  ));
or if you prefer json:

Code:
$this->object->xmlapi_query("cpanel", array("api.version"=>"1",
                                          "cpanel_jsonapi_user"=>"dominable",
                                          "cpanel_jsonapi_module"=>"ModSecurity",
                                          "cpanel_jsonapi_func"=>"list_domains",
                                          "cpanel_jsonapi_apiversion"=>"3"
  ));