Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

Call Uapi in WHM Plugin

Discussion in 'cPanel Developers' started by srkumar1986, Apr 12, 2018.

  1. srkumar1986

    srkumar1986 Member

    Joined:
    Mar 28, 2018
    Messages:
    13
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Coimbatore, Tamil Nadu
    cPanel Access Level:
    Root Administrator
    Hello,

    I have some issues in calling Perl module function from WHM Plugin using uapi.

    I have read the document that says to call command line and web based.

    But, i have default function to load my dropdown list when form loading.
    Code:
    $gapp_details = $cpanel->uapi(
    'GAppMod', 'load_gapp_details'
    );
    
    <select id="int_gapp_id" onchange="js:getgappdetails(this.value)">
    <option selected value="0">Select Domain</option>
    <?php
    foreach ($gapp_details['cpanelresult']['result']['data'] as $values){
    ?> <option value="<?php echo $values ?>"><?php echo $values ?></option>
    <?php } ?>
    </select>
    
    PS : CPanel Version v68.0.36

    Appreciate your help on this please

    Thanks in Advance !
    Rajkumar
     
    #1 srkumar1986, Apr 12, 2018
    Last edited by a moderator: Apr 12, 2018
  2. srkumar1986

    srkumar1986 Member

    Joined:
    Mar 28, 2018
    Messages:
    13
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Coimbatore, Tamil Nadu
    cPanel Access Level:
    Root Administrator
    Thank you Lauren,

    I have one more clarification.

    If any of API process needs to be run only on whm root user, Lets take an example off lets encrypt SSL Certificate process, they are guide to run this process only on root.

    how i can achieve? what i should give the cpanel_jsonapi_user value?

    Accessing cPanel API2 functions via WHM API

    Based on the above forum details, i have given the cPanel username but it returns the error as "Permission Denied"

    Any other ways please.?

    Thank you!
    Rajkumar S
     
    #3 srkumar1986, Apr 13, 2018
    Last edited by a moderator: Apr 13, 2018
  3. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    428
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hello,

    You should be able to use the whmapi1 to call cPapi2 functions the cpanel_jsonapi_user should be the cPanel user w/no password specified. Can you show me an example of the API function you're using that's providing an error?
     
  4. srkumar1986

    srkumar1986 Member

    Joined:
    Mar 28, 2018
    Messages:
    13
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Coimbatore, Tamil Nadu
    cPanel Access Level:
    Root Administrator
    Hello,

    Here is my URL for reference.
    Code:
    https://mydomain.com:2087/cpsess####/json-api/cpanel?api.version=1&cpanel_jsonapi_user=root&cpanel_jsonapi_module=CertificateDetails&cpanel_jsonapi_func=createcertificate&cpanel_jsonapi_apiversion=3&domain_name=mytestdomain.com
    
    in this createcertificate i have system command to create lets encrypt ssl certificate that accessible only by root user.

    But i am getting the below error

    The user “root” is not associated with a cPanel account and cannot call cPanel API 2

    currently the plugin is in WHM Console. By default WHM Console will execute all process as root i hope.

    Please specify my mistake on this.

    thanks
     
    #5 srkumar1986, Apr 17, 2018
    Last edited by a moderator: Apr 17, 2018
  5. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    428
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hello,


    When running the API you shouldn't be using root as the user, you're running the command as root but the user should be the user you want to generate the certificate for. Furthermore, can you link me to the documentation of this API call, it looks like you're using a cPAPI1 function and I'd like to look at it further.


    Thank you,
     
  6. srkumar1986

    srkumar1986 Member

    Joined:
    Mar 28, 2018
    Messages:
    13
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Coimbatore, Tamil Nadu
    cPanel Access Level:
    Root Administrator

    Hello,

    Here is my updated link

    https://mydomain.com:2087/cpsess####/json-api/cpanel?api.version=1&cpanel_jsonapi_user=wpmnkme&cpanel_jsonapi_module=CertificateDetails&cpanel_jsonapi_func=createcertificate&cpanel_jsonapi_apiversion=3&domain_name=mytestdomain.com

    I have changed the username as per reply.

    After changing the URL, i have called the function again. But this time i had received Permission denied error.

    {"func":"createcertificate","apiversion":3,"module":"CertificateDetails","result":{"errors":["\"/root/letsencrypt/./certbot-auto certonly --staging --standalone -n -d mytestdomain.com\" failed to start: \"Permission denied\" at /usr/local/cpanel/Cpanel/API/CertificateDetails.pm line 120.\n"],"status":0,"messages":null,"metadata":{},"data":null}}

    The reference URL I've used as,

    Use WHM API to Call cPanel API and UAPI - Developer Documentation - cPanel Documentation

    Thank you!
     
  7. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    428
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hello,

    Thank you for that, but I'm looking for the API you're using for CertificateDetails, do you have that?

    Thank you,
     
  8. srkumar1986

    srkumar1986 Member

    Joined:
    Mar 28, 2018
    Messages:
    13
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Coimbatore, Tamil Nadu
    cPanel Access Level:
    Root Administrator
    Hello Lauren,

    The Perl Module CertificateDetails that you're looking for is custom developed.

    If you need, i will share it with you.

    Thanks
    Rajkumar S
     
  9. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    428
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
Loading...

Share This Page