The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel API authentication with security token

Discussion in 'cPanel Developers' started by Satish Dongol, Jun 15, 2015.

  1. Satish Dongol

    Satish Dongol Member

    Joined:
    Jun 15, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  2. weeming21

    weeming21 Member

    Joined:
    Jun 13, 2015
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Malaysia
    cPanel Access Level:
    Root Administrator
  3. Satish Dongol

    Satish Dongol Member

    Joined:
    Jun 15, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Nepal
    cPanel Access Level:
    Root Administrator
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  5. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    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
     
    #5 cPAndrewHodge, Jun 18, 2015
    Last edited: Jun 18, 2015
  6. Satish Dongol

    Satish Dongol Member

    Joined:
    Jun 15, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Nepal
    cPanel Access Level:
    Root Administrator
    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.
     
  7. Satish Dongol

    Satish Dongol Member

    Joined:
    Jun 15, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Nepal
    cPanel Access Level:
    Root Administrator
    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?
     
    #7 Satish Dongol, Jun 21, 2015
    Last edited by a moderator: Jun 22, 2015
  8. Satish Dongol

    Satish Dongol Member

    Joined:
    Jun 15, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Nepal
    cPanel Access Level:
    Root Administrator
    Hi Michael, could you please help me out here.
    I still am not able to use the security token that I have generated to access other features of the cpanel api. It gives me access denied error every time.

    Thanks
     
  9. rajdshah

    rajdshah Registered

    Joined:
    Jan 24, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  10. Darma

    Darma Member

    Joined:
    Jul 31, 2015
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  11. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page