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!

Extend API with Plugin

Discussion in 'cPanel Developers' started by Berenger Z, Dec 8, 2017.

  1. Berenger Z

    Berenger Z Registered

    Joined:
    Dec 8, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Montreal
    cPanel Access Level:
    Root Administrator
    Hello All!

    I didn't find a specific answer in the documentation of the DSK.
    I'd like to know how I could extend the WMH API to some of my custom plugin methods.
    Is there a way?

    My plugin is integrated in WHM, but I'd like to be able to extend it to be able to use it through the WHM API 1. How can I register endpoints and process them?

    Thank you
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,532
    Likes Received:
    1,966
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Berenger Z

    Berenger Z Registered

    Joined:
    Dec 8, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Montreal
    cPanel Access Level:
    Root Administrator
    Thank you! I didn't see the describe part in the hooks section, but I think it actually goes the other way for me.

    An example would be:

    My plugin browses all the accounts, and for each of them check the presence of a readme.txt in the public_html. If there is one, then the app parses it, and extracts a version number located in it (we have a specific architecture for our projects).
    That allows me to have, from the WHM, a quick overview at the versions present for all the accounts, and which accounts do not have such configuration.
    That code exists, and I would like to be able to call it from the WMH API 1 to get a JSON response.

    Taking an example from the WMH API 1, I would like, for example, to be able to call :
    https://hostname.example.com:2087/cpsess##########/json-api/my-own-action-get-global-configurations?api.version=1&user=username

    and get the JSON response using a method in my own plugin.

    Is there a way I do not see in the documentation?

    Thank you!
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,532
    Likes Received:
    1,966
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Berenger Z

    Berenger Z Registered

    Joined:
    Dec 8, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Montreal
    cPanel Access Level:
    Root Administrator
    Hum, I'm not sure I understand.
    - Limited to existing API functions - gotcha.
    - Custom script to run the commands - I have, and it already outputs to the UI/Panel online.

    After browsing UAPI, it seems that if I break down my logic in two layer, I could do something like:
    - Get list of existing accounts using the WHM API 1,
    - For each account, use the WHM to UAPI (Use WHM API to Call cPanel API and UAPI - Software Development Kit - cPanel Documentation) to call a specific Module (to be created) that would carry the logic of getting the version on that specific user.

    That would multiply the calls, but I should be able to rely on the API to do that. Do you agree? Or is there some restriction on that?

    Thank you
     
  6. Berenger Z

    Berenger Z Registered

    Joined:
    Dec 8, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Montreal
    cPanel Access Level:
    Root Administrator
    *… that would carry the logic of getting the version on that specific user (ie, searching for a readme file, and extracting data from it if present). An UAPI Module could do that in perl, I guess.
     
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,532
    Likes Received:
    1,966
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Thank you for the additional clarification. Yes, that's actually a viable solution. We document how to create custom UAPI modules at:

    UAPI - Custom UAPI Modules - Software Development Kit - cPanel Documentation

    Let us know if this helps.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice