cPanel Api 403 error with c#
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.
Thanks for reading and helping!
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!
Please sign in to leave a comment.
Comments
0 comments