cPanel API cURL - Creating a session
AnsweredHi all,
I am in need of guidance. I am an old hat with linux, computers, the web and development but I am struggling to actually start working with accessing cPanel via API. Partly it is confusion with APIs and UAPI. I'm going to ask questions, please answer those that you can.
- The docs all push towards using UAPI but I cannot work out what UAPI is. Can you explain this please?
- I cannot find a simple 'Hello World' example for accessing the cPanel API, does such a thing exist?
- I have generated an API token, which is required, but do i need to create a session token using it or can I just make API calls straight off?
- Can I use the API token I generated with UAPI as well as API v2?
- I am currently starting simple and using cURL but will want to move across to Python, is there an example of using Python, a cPanel-specific library or do I just use the 'requests' module?
Thanks for your time and patience.
|\/|artin
-
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 -
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 -
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 -
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 -
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 -
Gotcha - you'll start here:
There's too many to make a nice list, but the search tool will get you to the page you need.
0 -
Thanks, that's just what I need. Thanks for your assistance :-)
0 -
You're very welcome!
0
Please sign in to leave a comment.
Comments
8 comments