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.

How to get the main domain name of account from cPanel API [thro' 2082/2083 port]?

Discussion in 'cPanel Developers' started by nesanjoseph, May 3, 2011.

  1. nesanjoseph

    nesanjoseph Active Member

    Joined:
    Dec 31, 2010
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    I need a help. I am not able to find the API for getting the main domain name of a cPanel account. I would like to know if there is any cPanel API call similar to WHM's listacct function.

    I will have only the cPanel username & password and using this authentication I should call the API thro' 2082/2083 port and get the main domain of the account.

    Is that possible?

    Many thanks,
    Nesan Joseph R.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Re: How to get the main domain name of account from cPanel API [thro' 2082/2083 port]

    Hi Nesan,

    There's not a 'clean' API call for what you need. However, there's a unique way that you can get user variables, like the primary domain, for remote calls.

    Remote calls use the XML-API. There's a special API1 module called 'print' that will allow you access to the cPanel user's variables. When making the XML-API call you will want to pass the following values:

    1) your "module" key will have a value 'print'
    2) do not pass the "function" key
    3) your argument for the 'print' module will be '$CPDATA{\'DOMAIN\'}'

    So, if you were to manually construct an XML-API URL, it would look like this
    Code:
    https://$server:2083/xml-api/cpanel?cpanel_xmlapi_module=print&cpanel_xmlapi_apiversion=1&arg-0=%24CPDATA%7B%27DOMAIN%27%7D
    
    If you happen to be using the PHP XML-API client class you script would look something like this
    PHP:
    <?php
    include "xmlapi.php";

    $ip '10.1.1.1';
    $user 'my_cPanel_username';
    $pass 'cpanel_password';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($user$pass);
    $xmlapi->set_port(2083);
    #$xmlapi->set_debug(1);

    $xmlapi->api1_query($user'print','', array('$CPDATA{\'DOMAIN\'}'));

    ?>
    Regards,
    -DavidN

    FYI: 'DNS' should also be a valid CPDATA key for extracting the primary domain
     
  3. nesanjoseph

    nesanjoseph Active Member

    Joined:
    Dec 31, 2010
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Re: How to get the main domain name of account from cPanel API [thro' 2082/2083 port]

    Hi,

    Many thanks for your answer. That has worked and I got what I exactly needed.

    Thanks,
    Nesan Joseph R.
     
Loading...

Share This Page