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.

Accessing cPanel API2 functions via WHM API

Discussion in 'cPanel Developers' started by hlc, Feb 10, 2015.

  1. hlc

    hlc Member

    Joined:
    Feb 10, 2015
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Greets,

    I successfully access cPanel API 2 functions using Perl via https://127.0.0.1:2082/xml-api/cpanel using a normal account username/password (eg, addpop etc).

    I successfully access WHM API functions using Perl via https://127.0.0.1:2087/xml-api using the root username/password (eg, listaccts etc).

    However, I want to access cPanel API 2 functions via WHM for all accounts hosted on the server (using the root username/password, since I don't have the user's cPanel account password), as per https://documentation.cpanel.net/display/SDK/cPanel+API+2+-+Calls+from+the+WHM+API :

    Code:
    https://127.0.0.1:2087/xml-api/cpanel?cpanel_xmlapi_user=root&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=listpops
    But that fails with a 500/internal server error:

    Code:
    Could not setuid to root at /usr/local/cpanel/Whostmgr/XMLUI/cPanel.pm line 82.
    cpsrvd/11.48.0.9 Server at 127.0.0.1
    
    ...and here we are :)

    I'd appreciate any pointers - even if it means I'm doing something stupid. Is what I'm trying possible? I read somewhere that I can access all API services using the root/pw pair, but perhaps I'm mistaken.

    Thanks
    Henry
     
  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
    You should be able to access all cPanel API's via the 'cpanel' call with WHM API. That said, the user 'root' is probably not a cPanel user on your box. Try it out with one of the users with a valid cPanel account and let me know if you still have this problem.
     
  3. hlc

    hlc Member

    Joined:
    Feb 10, 2015
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks for the reply Andrew -

    Using a normal cPanel account user login works, but that requires the password for that user.

    I need access to the cPanel functions for ALL accounts using a single login (ie, root access). ie, the same way I can login to WHM API and create accounts, etc. I need that functionality for the cPanel API.
     
  4. hlc

    hlc Member

    Joined:
    Feb 10, 2015
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Put another way, is it possible to access the Cpanel API via WHM using a non-cpanel username (eg, root, as I do with normal WHM API calls) to perform typical cPanel related actions (eg, creating an email, listing emails, etc)?
     
  5. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Try the call exactly as you had it before, just swap cpanel_xmlapi_user=root to cpanel_xmlapi_user=someuser.

    You will still be authenticated as root but this just lets the API know to perform the action against that user. cPanel API's by design expect to know the username based on who makes the call, if you are calling it as root the API doesn't know what user to perform the action against. If you have any kind of password prompt you can also use the root or reseller password in place of the users but I don't think that should happen.
     
  6. hlc

    hlc Member

    Joined:
    Feb 10, 2015
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    [RESOLVED] Re: Accessing cPanel API2 functions via WHM API

    Thanks for the assistance, that's working. In the authentication I need to use root:password (consistently), and cpanel_xmlapi_user=someuser (and no password specified).
     
Loading...

Share This Page