Get number of allowed addon domains via cpanel API
Hi All,
I have looked for over 2 hours searching for how to get the number of allowed addon domains using the CPanel API. I have been able to do a surprising number of things and am quite pleased with how easy things are to do and how well documented most features are but I cannot figure out this one.
I have been accessing the API generally using XML-API and GET parameters like so:
(SiteURL)/xml-api/cpanel?cpanel_xmlapi_module=AddonDomain&cpanel_xmlapi_func=listaddondomains
I want to be able to keep track of the number of allowed addon domains in my DB so users don't make the request and get an error beforehand. I generally prefer to disable features as opposed to catching errors where possible (yes I catch errors as well).
I know I can get the package details querying the WHM API stuff and do that with my own reseller accounts but I can't see how to get it using the CPanel API. My users may have CPanel accounts on servers that I may not have a reseller account so I need to assume WHM access is not possible.
Thanks much for any help,
Roger D.
-
With using the WHM APIs out of the question, maybe this one will show what you need: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiStatsBar]StatsBar Module Documentation If not, you can pull the number of addon domains directly from cpdata as a variable: [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/ExpVarRef]Available cPanel Plugin Variables You're looking for this one: $CPDATA{"MAXADDON"}0 -
Hello :) Yes, the information in the previous post is likely the best way to obtain that data. Let us know how it works out. Thanks. 0 -
[quote="vanessa, post: 1586712">With using the WHM APIs out of the question, maybe this one will show what you need: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiStatsBar]StatsBar Module Documentation If not, you can pull the number of addon domains directly from cpdata as a variable: [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/ExpVarRef]Available cPanel Plugin Variables You're looking for this one: $CPDATA{"MAXADDON"}
Actually the StatsBar API looks quite promising - I'll give that one a try and post back results later. Hmmm, didn't see that one in the docs. That looks like it can consolidate several of my other calls as well into 1 call and then just parse the results. Thanks very much for the help, Roger D.0 -
Thanks much Vanessa for the direction. I'll post how I did it here in hopes it might help someone else out. This might seem 'long winded' to some but I like to see detailed explanations when I look for these things. My application is in ASP.NET C# but probably most of you folks use PHP and the process might be similar. My function to get the StatsBar stuff is as follows: public string funcCpanelGetStatsBarInfo(string strSiteURL, string strUser, string strPassword, string strDisplayItems) { string url = strSiteURL + "/xml-api/cpanel?cpanel_xmlapi_module=StatsBar&cpanel_xmlapi_func=stat&display=" + strDisplayItems; return funcGenericSender(url, strUser, strPassword); }
and my 'helper' function "funcGenericSender" is as follows. (I use this helper 'cause I call it all over the place.)public string funcGenericSender(string strURL, string strUser, string strPassword) { HttpWebRequest req = HttpWebRequest.Create(strURL) as HttpWebRequest; ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(strUser + ":" + strPassword)); req.PreAuthenticate = true; req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested; req.Headers.Add("Authorization", auth); req.UserAgent = "cPanel .NET C# authenticator script"; WebResponse resp = req.GetResponse(); Stream receiveStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); string content = reader.ReadToEnd(); if (content == "") { content = strURL; } return content; }
and I call the function to retrieve StatsBar info like so:string strDislayItems = "addondomains|subdomains"; //put whatever statsbar items you need above string strResult = funcCpanelGetStatsBarInfo(strHostingHostURL, strHostingUserName, strHostingPassword, strDislayItems);
where strHostingHostURL is like0 -
Glad you got it working. Thanks for updating everyone with the outcome, I'm sure it'll be helpful 0
Please sign in to leave a comment.
Comments
5 comments