{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
Hi there,
I have a Gravity Form on a Wordpress website. The goal is once it is filled out, it will create a cPanel account (along with other things).
I'm using WHM API 1 - Create an account. Then I get the error {"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}.
The specific code is below:
[CODE=php] public function create_account($cp_user) {
print 'Creating cPanel Account...';
$this->cp_user = $cp_user;
$url = "$this->server_address:2087/json-api/createacct?api.version=1&username=$this->cp_user&domain=$this->domain&contactemail=$this->email&dkim=1&frontpage=0&hasshell=1&language=en&owner=root&mxcheck=auto&owner=root&password=$this->password&plan=Inception";
$header[0] = "Authorization: whm root:$this->server_auth";
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
URLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $header);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
I've double check the authorization token and even increased permissions to everything to rule that out as a problem. I've tried on two different servers and both are giving the same problem. I've tried with an api token I know works from the command line. I've copied and pasted the code from curl to PHP converter. Still same issue. Anyone have a suggestion on what I am doing wrong?
I've double check the authorization token and even increased permissions to everything to rule that out as a problem. I've tried on two different servers and both are giving the same problem. I've tried with an api token I know works from the command line. I've copied and pasted the code from curl to PHP converter. Still same issue. Anyone have a suggestion on what I am doing wrong?
-
Hi @Matt Paplham , I'm not seeing any issues with API Token authorization on my end. I've tested it for creating an account and list accounts through Perl, PHP, and curl. You said you tried an API token that you know works from command line; is that using curl with the same createacct endpoint? Do the servers that you are testing on have a registered SSL certificate? If not, you'll need CURLOPT_SSL_VERIFYHOST,0
in your header of your PHP code and--insecure
in your curl over CLI.0 -
Thanks for your response. I appreciate your time. From the command line, I am using the same endpoint, yes. And yes, our servers have a registered SSL certificate. With a fresh mind this morning I have figured out it is something with how I've set up the variables. If I set the curl options using no variables, it works just fine. 0 -
I changed the following and it worked: [CODE=php] $url = $this->server_address.':2087/json-api/createacct?api.version=1&username='.$this->cp_user.'&domain='.$this->domain.'&contactemail='.$this->email.'&dkim=1&frontpage=0&hasshell=1&language=en&owner=root&mxcheck=auto&owner=root&password='.$this->password.'&plan=Inception'; $header[0] = 'Authorization: whm root:'.$this->server_auth;
I'm fairly new to PHP, but I thought either way would work. At any rate, thanks for all your help.0
Please sign in to leave a comment.
Comments
3 comments