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.

xml-api avaliable yet ?

Discussion in 'cPanel Developers' started by jameshsi, May 23, 2007.

  1. jameshsi

    jameshsi Well-Known Member

    Joined:
    Oct 22, 2001
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It is available for those running cPanel/WHM 11 (EDGE and CURRENT builds as of right now).

    It's actually pretty simple. Are you familiar with reading data from a URL in PHP? It's the same thing. When the documentation states call a URL, you are merely fetching data from a URL - that data being in XML format.

    Example URL:
    https://domain.com:2087/xml-api/setupreseller?user=bob&makeowner=1

    The parameters you pass depending on the API call, consult the API documentation for details. Essentially you are just opening that URL and the data returned will be the XML formatted information you are requesting (or status information for an action you have performed).
     
  3. jameshsi

    jameshsi Well-Known Member

    Joined:
    Oct 22, 2001
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    As always, cpanel always saving words when it comes to documentation, seems people in cpanel don't like to type more words. If you put something like "this documentation is only for WHM 11", we can save time to even try the xml-api. :(
     
  4. maxstudios

    maxstudios Member

    Joined:
    Dec 1, 2003
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    In addition to this.... can the cPanel doc guys produce a full list of usage commands which are implimented inside the api, from creation of an account (which exists) to changing a password (which doesnt)..

    Cheers
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You mean like http://www.cpanel.net/plugins/xmlapi/index.html ?
     
  6. maxstudios

    maxstudios Member

    Joined:
    Dec 1, 2003
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    hi cPanelDavidG,

    There are a few functions on there that there isnt any documentation for... for example passwd.

    I know as cp11 is still under development but it would be handy to have.

    Also, does the xml api still use the original authentication method.??....

    Cheers
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I'll be sure to nag the folks that maintain our website once they're back in the office :)

    The XML API uses the same authentication method (HTTP Authentication) as the WHM interface. As a result, you do not need a remote access key with the XML API.
     
  8. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Does this mean I can use this API only inside WHM? I can not use the api to create an account outside whm, for example integrated in my customer management scripts?

    Michael
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It wouldn't be much of an API (intended for third party scripts) if you could only use it inside WHM :)

    You can call the entire URL directly (ex: https://sample.ext:2087/xml-api/listaccts?searchtype=user&search= ), and use whatever functions in the language you are using that handle HTTP Authentication to handle the HTTP Authentication properly :)
     
    #9 cPanelDavidG, Jun 6, 2007
    Last edited: Jun 6, 2007
  10. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for the information, but why not using the remote access hash? I hate it, when I need to specify the root password in my php scripts.
     
  11. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I'd recommend creating a separate account with root-level privileges in WHM to avoid placing your root password in a PHP script.
     
  12. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    The has will work as well.
     
  13. AlexAT

    AlexAT Well-Known Member
    PartnerNOC

    Joined:
    May 23, 2003
    Messages:
    203
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    Why don't you be so kind to place PHP code showing the use of this method?
    You did this for "cPanel::Accounting Modules" but seems XML API much powerfull.
     
  14. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Very quick and dirty PHP code for using the XML API from PHP:


    $apiPath = "/xml-api/listaccts?searchtype=user&search=";

    $result = file_get_contents("http://$user:$pass@localhost:2086$apiPath");

    echo $result;


    Be sure to set $user and $pass to your username and password.

    I'd recommend you use https:// and port 2087 if that option is available to you on your servers :)
     
  15. AlexAT

    AlexAT Well-Known Member
    PartnerNOC

    Joined:
    May 23, 2003
    Messages:
    203
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    So simple :)
    Will try, thank you!
     
  16. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    But how can I add the hash in the url? Can you make an example?
     
  17. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    You have to sent into in the authentication header
     
  18. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Would it be possible to give us an example? I think a lot of people try to use the api at the moment. It works perfectly when i use the root login details in the url, but I think that's definitly the wrong and insecure way to do it. You would for sure help a lot of people with an example to write more secure scripts.

    Thanks
    Michael
     
  19. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    ($page, $result, %headers)
    = Net::SSLeay::post_https('demo.cpanel.net', 2087, '/xml-api/listaccts',
    Net::SSLeay::make_headers('Authorization' => 'WHM ' . $authstr,'Connection' => 'close'),
    $formdata);

    where $authstr is the access hash
     
  20. AlexAT

    AlexAT Well-Known Member
    PartnerNOC

    Joined:
    May 23, 2003
    Messages:
    203
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    Any php example? :)
     
Loading...

Share This Page