The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WHM xmlApi call UAPI functions

Discussion in 'cPanel Developers' started by phoenixweb, Oct 21, 2014.

  1. phoenixweb

    phoenixweb Well-Known Member

    Joined:
    Jun 3, 2004
    Messages:
    68
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
    Dears,

    i would like to make a call to the new UAPI functions from the WHMapi instead of use API1 / API2 methods.
    Is it possible? Do WHMapi still need to use old obsolete methods?
    Can you help me?
     
  2. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    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?
     
  3. phoenixweb

    phoenixweb Well-Known Member

    Joined:
    Jun 3, 2004
    Messages:
    68
    Likes Received:
    0
    Trophy Points:
    6
    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
     
  4. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    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.
     
  5. phoenixweb

    phoenixweb Well-Known Member

    Joined:
    Jun 3, 2004
    Messages:
    68
    Likes Received:
    0
    Trophy Points:
    6
    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).
     
  6. phoenixweb

    phoenixweb Well-Known Member

    Joined:
    Jun 3, 2004
    Messages:
    68
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
  7. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    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.
     
  8. Alex Moleiro

    Alex Moleiro Registered

    Joined:
    Mar 11, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
    #8 Alex Moleiro, Mar 11, 2015
    Last edited by a moderator: Mar 11, 2015
  9. cPDavidN

    cPDavidN cPanel Developer
    Staff Member

    Joined:
    Mar 19, 2013
    Messages:
    42
    Likes Received:
    3
    Trophy Points:
    8
    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
     
  10. Alex Moleiro

    Alex Moleiro Registered

    Joined:
    Mar 11, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  11. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    This document should help:

    Guide to API Authentication

    Thank you.
     
  12. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    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.
     
    #12 cPAndrewHodge, Mar 16, 2015
    Last edited: Mar 16, 2015
  13. cPDavidN

    cPDavidN cPanel Developer
    Staff Member

    Joined:
    Mar 19, 2013
    Messages:
    42
    Likes Received:
    3
    Trophy Points:
    8
    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.
     
  14. kjg

    kjg Well-Known Member

    Joined:
    Mar 2, 2004
    Messages:
    147
    Likes Received:
    0
    Trophy Points:
    16
    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"
      ));
    
     
Loading...

Share This Page