Introduction


cPanel API 2 accesses cPanel account information and modifies settings.


  • If the desired function is available, we recommend that you use our newer UAPI functions.
  • You cannot call this API's functions via another API's call methods. For more information, read the API method distinctions section below.

Basic usage





https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Module&cpanel_jsonapi_func=function&parameter="value"

Unless you call this API via the WHM API, you cannot call this API via WHM's ports (2086 or 2087).




Currently, individual function documentation does not include Template Toolkit examples.


[%- 
USE Api2;
SET myvariable = execute( 
     'Module', 'function',
    {
        'parameter'      => 'value', 
        'parameter'      => 'value', 
        'parameter'      => 'value', 
    }
);
%]



$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
  
// Call the function.
$my_variable = $cpanel->api2(
    'Module', 'function',
    array(
        'parameter'      => 'value', 
        'parameter'      => 'value', 
        'parameter'      => 'value', 
    ) 
 );

 



my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Call the function.
my $my_variable = $cpliveapi->api2(
    'Module', 'function',
    {
        'parameter'      => 'value', 
        'parameter'      => 'value', 
        'parameter'      => 'value', 
    }
);

 


<?cp Module::function (
     template,
     returns,
     returns
     )
          parameter="value",
          parameter="value",
          parameter="value",
?> 




cpapi2 --user=username --output=type Module function parameter=value parameter=value  


cPanel & WHM introduced the command line feature in version 56.

cPanel API 2 calls through the command line consist of the following basic parts:

 

 

 

 

PartDescription
Command

This value is always cpapi2 for calls to cPanel API 2.


If you run CloudLinux™, you must use the full path of the cpapi2 command: 

/usr/local/cpanel/bin/cpapi2



Output Type

The API output type that you wish to receive.

  • Use --output=json to return JSON-formatted output.
  • Use --output=jsonpretty to return indented JSON-formatted output.
  • Use --output=xml to return XML-formatted output.
  • Use --output=yaml to return YAML-formatted output.

This parameter defaults to --output=yaml.


ModuleThe cPanel API 2 module name.
FunctionThe cPanel API 2 function.
UserThe cPanel account-level username.
Input parameters and values

The function's input parameters and their values.

  • You must URI-encode values.
  • Separate multiple parameter=value pairs with a space character.
  • Special characters within a key's value may cause an error. You must either escape any special characters within values or surround the value with appropriate quotes. For more information, read Wikipedia's Escape Characters article. For example, a bash shell command with a JSON-encoded value may appear similar to one of the following:
    • cpapi2 --user username Module function key=[\"sslinstall\",\"videotut\"]"
    • cpapi2 --user username Module function key='{"videotut","sslinstall"}'


For more information about this feature, run the following command:

cpapi2 --help





This example uses the following variables:


VariableDescriptionExample
ModuleThe function's module.Email
functionThe cPanel API 2 function.addpop
parameter

An input parameter's name.

cPanel API 2 functions use named arguments.


domain
value

The input parameter's value.

example.com
template

For cPanel tag function calls only, markup language that defines how the function's output displays.

For more information, read our Deprecated cPanel Tag Usage documentation.

%[br /]
returns

For cPanel tag function calls only, a comma-separated list of return parameters, to limit the function's output.

For more information, read our Deprecated cPanel Tag Usage documentation.

reason,result

Custom Event Handlers and Standardized Hooks

You can use the Standardized Hook System to customize the events before and after a cPanel API call.

API method distinctions