Question
How do you use cPanel's APIs from the command line?
Answer
The cPanel software provides two APIs that you can use to perform common management tasks using scripts instead of the interface. These include:
- UAPI: Access and modify cPanel account data and settings
- WHM API 1: Perform server administration tasks
The APIs can be called with their respective commands, but you may also need to use the absolute path to the binaries to call them:
# uapi
# /usr/local/cpanel/bin/uapi
Calling a uapi command requires the cPanel user, for example, to get a list of all of a user's domains:
# uapi --output=jsonpretty --user=$USERNAME DomainInfo list_domains
Note: The --output=jsonpretty is optional and only makes the output more human-readable on the command line.
# whmapi1
# /usr/local/cpanel/bin/whmapi1
Calling a whmapi is done as the user you are logged in as, typically root or a reseller. This will get a list of all cPanel accounts:
# whmapi1 --output=jsonpretty listaccts
Note: The --output=jsonpretty is optional and only makes the output more human-readable on the command line.
The functions for these respective APIs are listed in our development documentation. Each available function will include an example of how to use it through the command line:
Comments
0 comments
Article is closed for comments.