Need help with cPanel API 2 authentication

janvv

Registered
Nov 8, 2020
2
0
1
Kortenhoef, Netherlands
cPanel Access Level
Website Owner
Hi there,

My provider uses cPanel and I am trying to use the api to create a TXT record in my DNS zone.
I created an API key, and use this page to see which call I need to do: Cpanel API 2 ZoneEdit

So, in my case it should be:
Code:
https://domain.com:2087/<MY_API_KEY>/json-api/cpanel?cpanel_jsonapi_user=vanveldh&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=add_zone_record&domain=domain.com&name=_acme-challenge&type=TXT&txtdata="test"&class=IN
I keep getting "access denied". I tried port 2083. I tried to move the user and key to an authentication header. Nothing helps...

What am I doing wrong?

The documentation isn't very clear if it should be a GET or POST request. But I tried both in Postman.
 
Last edited by a moderator:

janvv

Registered
Nov 8, 2020
2
0
1
Kortenhoef, Netherlands
cPanel Access Level
Website Owner
I finally got it working :cool:

GET or POST does not matter. Both work.
Port number is 2083
You have to use your username and password in the header as basic authorization:

Creating the TXT record:

Code:
curl --location --request POST \
 'https://papasmurf.nl:2083/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=add_zone_record&domain=papasmurf.nl&name=_acme-challenge&type=TXT&txtdata=blahblah&class=IN&ttl=3600' \
--header 'Authorization: Basic <my userid and pwd base64 coded>'
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,173
787
313
cPanel Access Level
Root Administrator
I spoke with one of the devs today and they couldn't reproduce the odd behavior I was seeing last night on my end, so it seems there may have been an issue with my testing environment itself.

I'm glad you got this working, but please reach out if you need anything else.