Get number of allowed addon domains via cpanel API

rdouglass

Registered
Mar 3, 2014
3
0
1
cPanel Access Level
Reseller Owner
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.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,201
363
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.
 

rdouglass

Registered
Mar 3, 2014
3
0
1
cPanel Access Level
Reseller Owner
With using the WHM APIs out of the question, maybe this one will show what you need:

StatsBar Module Documentation

If not, you can pull the number of addon domains directly from cpdata as a variable:

Available cPanel Plugin Variables


You're looking for this one:

Code:
$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.
 

rdouglass

Registered
Mar 3, 2014
3
0
1
cPanel Access Level
Reseller Owner
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:

Code:
        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.)

Code:
        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:

Code:
string strDislayItems = "addondomains|subdomains";
//put whatever statsbar items you need above
string strResult = funcCpanelGetStatsBarInfo(strHostingHostURL, strHostingUserName, strHostingPassword, strDislayItems);
where

strHostingHostURL is like https://mydomain.com:2083

strHostingUserName and strHostingPassword should be obvious as the cpanel account username and password.

Then parse the output and do what you n

The code is in classes and separate files in my app but this is essentially how I did it. Again probably long-winded for some but maybe enough information for someone else to see exactly what to do.

Thanks again for the help.
Roger D.