baroninn

Active Member
Jan 31, 2018
28
2
53
Iceland
cPanel Access Level
Root Administrator
I just found out that WP-toolkit has a rest api.
fantastic... I could really really use it.
I found it by going into WHM -> WP-Toolkit -> Settings- > Open REST API documentation.

in there we see three options:
1. Servers
2. host
3. cpanelOrWhmSecurityToken

I can use this swagger webGUI to make my API calls, and I get the results successfully.
but I cannot for the life of me get this to work outside of WebGUI.... for example if im using Visual Studio Code with REST API extension.

here is what I believe should be the correct way:

first get a Security Token (/0123456789):
to get a security Token, I read in your API doc's I should do this:
GET https://domain.tld:2087/json-api/create_user_session?api.version=1&service=cpaneld&user=[customerCpanelUserName]
Authorization: whm root:[API_TOKEN]


or if you are going to use the WHM server method:

GET https://domain.tld:2087/json-api/create_user_session?api.version=1&service=whostmgrd&user=root
Authorization: whm root:[API_TOKEN]


Calling these api requests, I get a successful response that includes the session_token that looks like this (/0123456789), and some more interesting results... like a SSO url.
ok... so then I should be able to make another API request to the WP-toolkit rest API service using this user_session token ?? correct ??,, something like this:

GET https://domain.tld:2083/0123456789/3rdparty/wpt/index.php/v1/installations?sortBy=title&sortOrder=asc
Accept: application/json
Authorization: Basic [API_TOKEN]


or if you want to make the request to the WHM side:

GET https://domain.tld:2087/0123456789/cgi/wpt/index.php/v1/installations?sortBy=title&sortOrder=asc
Accept: application/json
Authorization: Basic [API_TOKEN]


but no matter what I try, I just cannot make this work...
and I have tried almost everything.
I just get Token denied. and the results are just html.... most of the times just the login screen html.

I have also tried to use Authorization: whm root:[API_TOKEN]....
but I also get Token denied.

I have tried creating a session_token with different API version.. but it does not work.

so.... :
what is the correct way of making requests to the WP-toolkit REST API, remotely ?
authenticating and then making the request it self.
 

OfficialHax

Member
Oct 2, 2020
14
6
78
Ulefoss, Norway
cPanel Access Level
Root Administrator
Hi Baroninn.

You have authorised your endpoints at Open WP Toolkit > 'Global Settings' > 'Open REST API documentation' right?
image_2023-02-23_140127196.png

I don't think you would be able to authorise localhost. Have you tried sending the calls from an a open host?
 
Last edited:
  • Like
Reactions: cPRex

baroninn

Active Member
Jan 31, 2018
28
2
53
Iceland
cPanel Access Level
Root Administrator
no no no...
The WebGUI works perfectly..,... all you need to do is choose the correct server, fill in the host and then manually type in the SecurityToken.
But thats not what im trying to do.

im trying to make API calls to the WP-toolkit REST API from external source....... not localhost.
 

GabrielaPeterson

Registered
May 18, 2023
1
0
0
USA
cPanel Access Level
Reseller Owner
It's awesome that you discovered WP-toolkit's REST API! It can be a game-changer, right? However, I understand that you're facing some challenges when trying to use it outside of the WebGUI, like in Visual Studio Code with the REST API extension.