cPanel API authentication with security token

Satish Dongol

Member
Jun 15, 2015
6
0
1
Nepal
cPanel Access Level
Root Administrator
Hi everyone. I have been working on a project which will allow users to login to their cpanel account from a third party application. I have successfully used the PHP script to remotely login to the cpanel account and generated a security token from it.

How ever now I want to be able to access the cPanel's much vast API to access its data. I want to use the API with the security token that I have generated, but all the examples seems to use username/password authentication.

I would appreciate it if anyone can point me to a right direction.

Thanks
 

AndrewH.

Well-Known Member
Dec 10, 2012
52
3
83
cPanel Access Level
Root Administrator
If you have already authenticated and generated your security token the API calls should just work. Use the API shell in either WHM or cPanel to see what the urls generated for API calls are but it should be a near drop in replacement.

Ex:

API shell will generate this as the url:

Code:
/execute/Branding/include
With this you just need

$serverurl:2083/$sessionToken/$url

so the API call is this:


Code:
https://mytestserver.com:2083/cpsess123456/execute/Branding/include
 
Last edited:

Satish Dongol

Member
Jun 15, 2015
6
0
1
Nepal
cPanel Access Level
Root Administrator
Hello,

The following document is a good place to start:

Guide to API Authentication

Could you let us know if this document helps?

Thank you.
Thanks for the reply. Actually I have gone through the documentation mentioned in the above link, but in the documentation all the authentication is done using username and password. Could you please lead me in right direction.
 

Satish Dongol

Member
Jun 15, 2015
6
0
1
Nepal
cPanel Access Level
Root Administrator
If you have already authenticated and generated your security token the API calls should just work. Use the API shell in either WHM or cPanel to see what the urls generated for API calls are but it should be a near drop in replacement.

Ex:

API shell will generate this as the url:

Code:
/execute/Branding/include
With this you just need

$serverurl:2083/$sessionToken/$url

so the API call is this:


Code:
https://mytestserver.com:2083/cpsess123456/execute/Branding/include
Thanks for the response. I have generated the security token by using the cPanel's loginmein class for PHP. I first generated the logged in URL from the script found here: gist.github.com/kmark/4440574. From that URL I extracted the security token.

Now my problem is that, if I load the URL generated by the script then I can use the security token to make API calls, but since I am just extracting the security token from the URL it is giving me "Access Denied" error. This is because the cookies of the cPanel is not being created.

Could you help me further based on the above mentioned details?
 
Last edited by a moderator:

rajdshah

Registered
Jan 24, 2008
2
0
51
Hello, Why do you need security token when you're trying to access cPanel API? REST calls works without any security token. Which programming language are you using? PHP or something else?
 

Darma

Member
Jul 31, 2015
5
0
1
Belgium
cPanel Access Level
Reseller Owner
Hi guys,

Sorry to jump here, but how can I generate that security token. I have tried several solutions I have found everywhere, but I cannot manage. I can login well.

I need to get the security token and redirect user to the awstat page of his website.

Thanks for any help you can give me.

Kind regards,

Darma
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Sorry to jump here, but how can I generate that security token. I have tried several solutions I have found everywhere, but I cannot manage. I can login well.
Could you elaborate on the type of script you are using, and what methods you have tried thus far? Is the Guide to API Authentication document helpful?

Thank you.
 

mer30boy

Registered
Feb 16, 2020
3
0
1
iran
cPanel Access Level
Website Owner
hi
i want to use the PHP script to remotely login to the cpanel account and generate a security token from it.
do you have a php example ?