Skip to main content

cPanel API cURL - Creating a session

Answered

Comments

8 comments

  • Martin Ward

    As a follow-up, I have been trying different cURL commands and they pretty much al return with:

    <p>Token authentication allows access to UAPI or API 2 calls only.</p>

    My latest failure was:

    $ curl -u 'user:password' -H"Authorization: cpanel user:TOKEN" "https://example.com:2083/ServerInformation/get_information?api.version=2.0"

    I've tried it with and without "?api.version=2.0" at the end of the URL.

    I've tried it with and without the "-u user:password".

    The result is the same as detailed above.

    0
  • cPRex Jurassic Moderator

    Hey there!  I'll answer these in order to make sure nothing gets missed:

    1- I like to think of the cPanel API as two levels - just like there is a WHM for root tasks and a cPanel for user tasks, there is a whmap1 and uapi system for those types of calls.

    2 - No, that isn't really how it works.  You call a specific API to perform the function you want.

    3 - My best answer to this is "maybe" but in your case probably not.  You only need the session if you want to access a specific service as the user.  https://api.docs.cpanel.net/specifications/whm.openapi/session#/specifications/whm.openapi/session/session-create_user_session.  For most calls involving a URL, it will create a new session for your specific work automatically.

    4 - No - this is covered in the blue notification box here - https://docs.cpanel.net/knowledge-base/security/how-to-use-cpanel-api-tokens/

    5 - Correct, you would just use the "requests" module to get this working inside other code.

    0
  • Martin Ward

    Thanks for the responses. 

    1. My tools will be accessing cPanel at the user level so I will use UAPI for my needs. These will are simply going to speed up the tasks that I would otherwise have to do using the web interface.

    2. Understood, thank you.

    3. Given that the number of tasks a tool will be required to do is going to be small (add a new domain and create three email boxes or display the domain information) I doubt I will need a session. There will be no interaction between my tool and the user.

    4. Thank you. I can use the API token for both UAPI and APIv2 calls, just not the API ones.

    So that leaves one final question: Where are the cPanel function documents? I'm trying to find a reference document but my search-fu is not up to scruff this week, sadly.

    0
  • cPRex Jurassic Moderator

    Can you let me know what you mean when you say "cPanel function documents"?  Anything that's a uapi call would be related to user level tools.

    0
  • Martin Ward

    OK so as an example I will want to add a new domain that I have bought and then create an email address for it. 

    In the web interface I would login, then:

    Click [Domains]
    Click [Create a new domain]
    Type in the new domain and click [Submit]

    Then I would:

    Click [Email accounts]
    Click [+Create]
    Select the domain
    Type in the user name
    Type in a password
    Click [+Create]

    I understand that this can be done via the API but how do I find out what API calls to make?

    I am expecting there to be a document that provides a list of API calls and descriptions of what each of them do, or alternatively a list of the web interface functions and a link to their API alternatives.

     

    0
  • cPRex Jurassic Moderator

    Gotcha - you'll start here:

    https://api.docs.cpanel.net/

    There's too many to make a nice list, but the search tool will get you to the page you need.

    0
  • Martin Ward

    Thanks, that's just what I need. Thanks for your assistance :-) 

     

    0
  • cPRex Jurassic Moderator

    You're very welcome!

    0

Please sign in to leave a comment.