SOLVED Calling cPanel API 2 with curl

kenavn

Registered
Jan 3, 2020
1
0
0
Oslo
cPanel Access Level
Website Owner
I need to call the ZoneEdit module in the API2 as a end user. I cannot rely on a third party library or similar.

I have tried all I can think of for hours, spanning from authenticating with API tokens, basic http etc.

Can someone please just for me, and for everyone else, give a clean and unconvoluted example of how to achieve this using either basic auth or token auth? Alternatively, how do I successfully acquire a security token (embedded in the url) with basic auth before actually doing the API-call?

The thing is that I think I have found descriptions of this scattered around in the docs and online - but I cannot successfully authenticate.

A later example:

https://cpanelserver:2087/json-api/...el_jsonapi_func=fetchzones&domain=example.com (With basic http authentication and with API-token based authentication):

{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}

Is there something my ISP has blocked? I guess I am trying to reach API2 via the WHM API. I just cannot find any examples in the docs on how to interact with the API2 directly. Anyone knows?

I am totally lost here.
 

cPanelTJ

Product Owner
Staff member
Jan 29, 2019
97
49
93
Houston, TX
cPanel Access Level
Root Administrator
Twitter
Hi @kenavn ,

The root of the problem you are experiencing is due to your request attempting to connect to WHM (port 2087) instead of cPanel (port 2083). Additionally, although it isn't causing any problems, the API 2 ZoneEdit::fetchzones call does not accept any parameters, such as 'domain'.

To acquire a cPanel API Token, you can manually do it in cPanel >> Home >> Security >> Manage API Tokens or use the UAPI Tokens::create_full_access.

The resulting curl should look something like this:

Code:
curl -H 'Authorization: cpanel $user:$token' 'https://127.0.0.1:2083/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=fetchzones'
 
Last edited: