Is there a reliable way to retrieve an account's primary domain name via the XML API and only the cPanel account's login details? I've looked the API1/2 modules over and nothing stands out as a winner.
Is there a reliable way to retrieve an account's primary domain name via the XML API and only the cPanel account's login details? I've looked the API1/2 modules over and nothing stands out as a winner.
Hi That1Swede,
You should be able to retrieve the primary domain by using 'listaccts'
will produce something like:Code:$searchtype = 'user'; $searchforme = 'dave'; //my username is 'dave' and my primary domain is dave.test print $xmlapi->listaccts($searchtype, $searchforme);
from there you can grep the domain node.Code:<listaccts> <acct> <disklimit>unlimited</disklimit> <diskused>0M</diskused> <domain>dave.test</domain> <email>dave@cpanel.test</email> <ip>192.168.1.1</ip> <maxaddons>*unknown*</maxaddons> <maxftp>unlimited</maxftp> <maxlst>unlimited</maxlst> <maxparked>*unknown*</maxparked> <maxpop>unlimited</maxpop> <maxsql>unlimited</maxsql> <maxsub>unlimited</maxsub> <owner>masterowner</owner> <partition>home</partition> <plan>default</plan> <shell>/bin/bash</shell> <startdate>10 Mar 12 07:08</startdate> <suspended>0</suspended> <suspendreason>not suspended</suspendreason> <suspendtime></suspendtime> <theme>x3</theme> <unix_startdate>1268399296</unix_startdate> <user>dave</user> </acct> <status>1</status> <statusmsg>Ok</statusmsg> </listaccts>
If you mean by "primary" the "owner's" domain, then there's no direct function for that. You'll need to create you own iterative code block to check the 'owner' tag to see if it matches 'root' or the username. Either case, you will have queried and received the authoritative user (and their domain info!).
Hope that helps,
-Dave
David Neimeyer
Integration Developer
sdk.cpanel.net
APIs: XML-API API1 & API2
Check Out: Developer Downloads Integration Blog
Need Support? Support Ticket Developer Forum Feature Request
I considered listaccts however with only cPanel access to the account (and not WHM access) it's not an option in this case. I was hoping for an API1/2 call of sorts.
So, with only the login details for a cPanel account is there a way to reliable fetch the account's main domain (ie. the domain name the cPanel account was created with)?
That1Swede,
I'm sorry, I misunderstood that cPanel credentials were the limiting factor.
To my knowledge there's no direct way to do what you want. However, there are a few indirect ways to obtain that information.
1) write your own cpanel module that answers api calls:
WritingCpanelModules < DeveloperResources/ApiBasics < TWiki
2) create a cPanel branding page (or modify an existing one) that contains/returns an ExpVar
This first way is much better but would require some knowledge of Perl. The second way is kind of a shift in methodology. That's to say, if you do create a page with this tag, you'd have to retrieve that page directly.Code:<cpanel print=$CPDATA{'DOMAIN'} >
Additionally, $CPDATA{'DOMAIN'} only contains the immediate user's domain, and there's no knowledge of a parent or owner account (I was unclear if that matters).
Lastly, you'd need root to implement either #1 or #2
3) along the lines of #2, you could just login and parse the index.html page. If you're using the x3 theme: use cURL to login and fetch index.html. Then create a DOM object of html and use XPath and search for a table with id="stats", grab the second cell of the first row
Hope this helps. If I can think of anything else, I'll be sure to post.Code:<table id="stats" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr class="row-even"> <td class="stats_left">Main Domain</td> <td class="stats_right"><b>therewillbecake.net</b></td> </tr>.....
-Dave
David Neimeyer
Integration Developer
sdk.cpanel.net
APIs: XML-API API1 & API2
Check Out: Developer Downloads Integration Blog
Need Support? Support Ticket Developer Forum Feature Request
Thanks for the suggestions, as I won't have root access to the servers that the script will be interfacing with I won't be able to go the module or branding route. I was hoping I wouldn't have to scrape HTML to get the information (as the account could be using any random theme and thus it'd be a bit of 'hit and miss').
The 'listaddondomains' function in the 'AddonDomain' module can be used to grab the info provided that there is at least one addon domain set up under the account as it returns a 'rootdomain' entry for each addon domain that is set to the account's primary domain.
Any chance of having the account's primary domain added to the 'StatsBar' module's 'stat' function in some way in the future, perhaps? ;P
That1Swede,
My colleague, Matt, and I got solid answer for you!
result:Code:http://yourserver:2082/xml-api/cpanel?cpanel_xmlapi_apiversion=1&cpanel_xmlapi_module=print&arg-0=DOMAIN
What we're doing is making a call to the <cpanel print="" > module. This hits the same code as in my #2 suggestion.Code:<?xml version="1.0" ?> <cpanelresult> <command>print</command> <type>internal</type> <source>internal</source> <apiversion>1</apiversion> <data> <result>dave.com</result> </data> <event> <result>1</result> </event> </cpanelresult>
Hope that works for you!
One note, if you're using our XMLAPI.php class, the api1_query() explicitly requires a module and function be specified for creating the request URL. The example URL only as the module, cause this module only has a single funciton (internally). You will have to modify the php wrapper class for this usage case...that is, like I said, if you're using it. Otherwise, just structure your query like the example above within your own code
Best Regards,
-Dave
PS. I agree about the StatsBar; had investigated that possibility previously too. I'll certainly make note to the powers that be![]()
David Neimeyer
Integration Developer
sdk.cpanel.net
APIs: XML-API API1 & API2
Check Out: Developer Downloads Integration Blog
Need Support? Support Ticket Developer Forum Feature Request
Dave,
Excellent. Much thanks for that.![]()