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.

Get number of allowed addon domains via cpanel API

Discussion in 'cPanel Developers' started by rdouglass, Mar 3, 2014.

  1. rdouglass

    rdouglass Registered

    Joined:
    Mar 3, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    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.
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,666
    Likes Received:
    646
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  4. rdouglass

    rdouglass Registered

    Joined:
    Mar 3, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner

    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.
     
  5. rdouglass

    rdouglass Registered

    Joined:
    Mar 3, 2014
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    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.
     
  6. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Glad you got it working. Thanks for updating everyone with the outcome, I'm sure it'll be helpful
     

Share This Page