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!

WHM API returns Token denied

Discussion in 'cPanel Developers' started by Ramize Attia, Jan 14, 2018.

  1. Ramize Attia

    Ramize Attia Member

    Joined:
    Jan 14, 2018
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    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?
     
  2. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,561
    Likes Received:
    42
    Trophy Points:
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Ramize Attia

    Ramize Attia Member

    Joined:
    Jan 14, 2018
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Alexandria, Egypt
    cPanel Access Level:
    Root Administrator
  4. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,561
    Likes Received:
    42
    Trophy Points:
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Ramize Attia

    Ramize Attia Member

    Joined:
    Jan 14, 2018
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    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
     
  6. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,561
    Likes Received:
    42
    Trophy Points:
    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.
     
    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