Ramize Attia

Member
Jan 14, 2018
10
1
3
Alexandria, Egypt
cPanel Access Level
Root Administrator
hi, I am using WHM API to automatically create cPanel accounts. I followed the documentation bu I am facing an issue with the token.

After creating the token in my WMH, I try the URL in the browser but it will only return this error
Code:
{"cpanelresult":{"apiversion":"2","error":"Token denied","data":{"reason":"Token denied","result":"0"},"type":"text"}}
I am using this line from the API documentation
Code:
https://hostname.example.com:2087/cpsess##########/json-api/createacct?api.version=1&username=user&domain=example.com&plan=package_name&featurelist=default&quota=0&password=12345luggage&ip=n&cgi=1&hasshell=1&contactemail=user%40seconddomain.com&cpmod=paper_lantern&maxftp=5&maxsql=5&maxpop=10&maxlst=5&maxsub=1&maxpark=1&maxaddon=1&bwlimit=500&language=en&useregns=1&hasuseregns=1&reseller=0&forcedns=1&mailbox_format=mdbox&mxcheck=local&max_email_per_hour=500&max_defer_fail_percentage=80&owner=root
* I changed all needed details in the URL.
* I have created the API token in the WHM.

What am I doing wrong here?
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,578
53
308
cPanel Access Level
Root Administrator
Hi,

How are you submitting the token via the browser?
Also, please link the documentation you and following, and what is the version number of cPanel & WHM you are using?
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,578
53
308
cPanel Access Level
Root Administrator
Hi,

How are you submitting the token via the browser? Are you adding it to the Authorization header? Are you appending it to the URL? Is there another method you are using?

Which version of cPanel & WHM are you using?
 

Ramize Attia

Member
Jan 14, 2018
10
1
3
Alexandria, Egypt
cPanel Access Level
Root Administrator
What I do is to change the values in the given URL to my actual values

Code:
https://hostname.example.com:2087/cpsess##########/json-api/createacct?api.version=1&username=user&domain=example.com&plan=package_name&featurelist=default&quota=0&password=12345luggage&ip=n&cgi=1&hasshell=1&contactemail=user%40seconddomain.com&cpmod=paper_lantern&maxftp=5&maxsql=5&maxpop=10&maxlst=5&maxsub=1&maxpark=1&maxaddon=1&bwlimit=500&language=en&useregns=1&hasuseregns=1&reseller=0&forcedns=1&mailbox_format=mdbox&mxcheck=local&max_email_per_hour=500&max_defer_fail_percentage=80&owner=root
I also try
Code:
https://hostname.example.com:2087/cpsess##########/json-api/createacct?api.version=1
and just paste in the browser and then it gives me this error.
Code:
{"cpanelresult":{"apiversion":"2","error":"Token denied","data":{"reason":"Token denied","result":"0"},"type":"text"}}
No other way, that's the only way I am using now, because I want to make sure it's working before implementing my code.
I am using version: 64.0.25
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,578
53
308
cPanel Access Level
Root Administrator
Hi,

Thank you for the information. API Token authentication doesn't work via the browser, at least not without using dev tools to modify the request headers. When you submit your test URL the browser should either use your existing session or exit with an error like:

Code:
"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
Information about using API tokens is in our Guide to API Authentication - API Tokens - Software Development Kit - cPanel Documentation guide.

The fact your error message is reporting a problem with the token suggests something else is wrong. Did you happen to mean version 68.0.25? We didn't publish 64.0.25.