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.

cPanel/WHM API v3

Discussion in 'cPanel Developers' started by ruyrocha, Nov 4, 2013.

  1. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
    Hey guys, I was using CustomEventHandler debugger and found some of v3 calls, e.g:

    Code:
    SSL:check_shared_cert
    $apiv = 3
    $type = post
    -----
    $cfgref
     
    $VAR1 = bless( {
                     '_args' => $VAR1
                   }, 'Cpanel::Args' );
     
     
    --------------------
    Branding:include
    $apiv = 3
    $type = pre
    -----
    $cfgref
     
    $VAR1 = bless( {
                     '_args' => $VAR1
                   }, 'Cpanel::Args' );
     
     
    --------------------
    contactus:isenabled
    $apiv = 2
    $type = pre
    -----
    $cfgref
     
    $VAR1 = {};
    
    Do you have anything documented to share with us? :D How can I make a successful call to cPanel API v3?
     
  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
    UAPI Module Listing

    UAPI is Api version 3. You can use the API Shell (in 11.40) to easily see nearly all the calls as it will literally parse the system for all API2, UAPI and WHM API1 calls. It will also parse 3rd party plugins for valid API calls.
     
  3. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
  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
    You can call them the same way you call API2 calls, just specify version=3 (this is how I've been using it internally anyway).
     
  5. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
    Hey @cPAndrewHodge, I'm still trying to call UAPI as root without success, e.g:

    Code:
    ➜  ~  curl -k -H $auth1 'https://dev2:2087/json-api/execute?user=sup&api.version=3&api.module=Ftp&api.function=get_port' ; echo  
    {"metadata":{"command":"execute","version":"3","reason":"Unknown app requested for this version (3) of the api.","result":0}}
    ➜  ~  curl -k -H $auth1 'https://dev2:2087/json-api/cpanel?user=sup&api.version=3&api.module=Ftp&api.function=get_port' ; echo 
    {"cpanelresult":{"apiversion":"2","error":"api call failed. Module name is required.","data":{"reason":"api call failed. Module name is required.","result":"0"},"type":"text"}}
    ➜  ~  curl -k -H $auth1 'https://dev2:2087/json-api/cpanel?user=sup&cpanel_jsonapi_version=3&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=get_port' ; echo 
    {"cpanelresult":{"data":{"result":0,"reason":"Could not find function 'get_port' in module 'Ftp'"},"error":"Could not find function 'get_port' in module 'Ftp'","module":"Ftp","apiversion":2,"func":"get_port"}}
    
    I've tried also to run it from command line, e.g:

    Code:
    /usr/local/cpanel/uapi --json-connect
    Do you have any thoughts here?
     
  6. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Looks like I gave you bad advice before, try this:
    Code:
    (UAPI)
    https://mydevserver:2083/sessionkey/execute/Ftp/get_port
    
    Code:
    (API2)
    https://mydevserver:2083/sessionkey/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=listftp
    Here's an example passing in arguments
    Code:
    /execute/Resellers/list_accounts?user=taco&anotherKey=burrito
    
    And here's one with filtering

    Code:
    /execute/Resellers/list_accounts?api.filter_column_0=user&api.filter_type_0=contains&api.filter_term_0=taco
    

    I highly recommend getting the latest 11.40 and playing with the API shell, it will make development a lot easier. To clarify, when I had specified swapping the version number it was mostly because my familiarity is using the CPANEL.api JavaScript object which we use to develop our pages with.
     
Loading...

Share This Page