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

nesanjoseph

Active Member
Dec 31, 2010
31
0
56
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.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
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
 

nesanjoseph

Active Member
Dec 31, 2010
31
0
56
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.