Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

cPanel Api 403 error with c#

Discussion in 'cPanel Developers' started by dangelob, Mar 23, 2018.

  1. dangelob

    dangelob Registered

    Joined:
    Mar 23, 2018
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Maastricht
    cPanel Access Level:
    Reseller Owner
    Hello everyone,
    I'm trying to make an request from the api in c#(I want to get information from the api)
    I'm stuck with an 403 error that I'm not allowed to make the request. The api works from the browser when I'm logged in.

    But I have 2 step verification enabled does this make an difference?
    Also, does it matter that I'm using the username and password instead of the api token? (I'm still new to the api, and using the api in c#)

    I would appreciate any help with this problem.

    Code:
                string baseurl = "https://DOMAIN:2087/cpsess#######/";
                string function = "json-api/cpanel?cpanel_jsonapi_user=USER&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=DiskUsage&cpanel_jsonapi_func=fetchdiskusage";
                WebRequest wreq = WebRequest.Create(baseurl + function);
    
                CredentialCache MyCredential = new CredentialCache();
                MyCredential.Add(new Uri("https://domain:2087/"), "Basic", new NetworkCredential("USERNAME", "PASSWORD"));
                wreq.Credentials = MyCredential;
    
                WebResponse wres = wreq.GetResponse();
                if (((HttpWebResponse)wres).StatusDescription == "OK")
                {
                    wres.Close(); //to free resources
                    label3.Text = "succesful";
                }
                else
                {
                    wres.Close(); //to free resources
                    label3.Text = "unsuccesful";
                }
    Thanks for reading and helping!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,711
    Likes Received:
    1,791
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Here are a couple of threads that might point you in the right direction:

    Get number of allowed addon domains via cpanel API
    cPanel login rejected with API through C#

    Username and password authentication is suitable for cPanel's APIs. API Tokens are available for use to authenticate with WHM’s APIs.

    Also, yes, two-factor authentication does require some additional steps. We document this at:

    Guide to API Authentication - Two-Factor Authentication - Developer Documentation - cPanel Documentation

    You can use an API token to authenticate with WHM’s APIs.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice