cPanel API cURL - Creating a session
Hi 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
Please sign in to leave a comment.
Comments
2 comments