Introduction

cPanel API 1 accesses information from the cPanel interface.

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




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



my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
my $your_variable = $cpliveapi->api1('Module', 'function', ['parameter', 'parameter', 'parameter'] ); # Call the function.



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


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


<cpanel Module="Module::function( $FORM('parameter','parameter','parameter') )">




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


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

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

PartDescription
Command

This value is always cpapi1 for calls to cPanel API 1.

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

/usr/local/cpanel/bin/cpapi1



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 1 module name.
FunctionThe cPanel API 1 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:
    • cpapi1 --user username Module function key=[\"sslinstall\",\"videotut\"]"
    • cpapi1 --user username Module function key='{"videotut","sslinstall"}'


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

cpapi1 --help





These examples use the following variables:


VariableDescriptionExample
ModuleThe module for the function that you wish to use.Email
functionThe cPanel API 1 function that you wish to use.addpop
parameter

Input parameters that you pass to the function.

  • cPanel API 1 functions use ordered parameters. You must specify parameters in the order in which they appear in this documentation.
  • cPanel API 1 parameters are case-sensitive.

example.com

Call cPanel API 1 from the WHM API

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

You can use the WHM API to call cPanel API functions. For more information, read our Use WHM API to Call cPanel API & UAPI documentation.

Because some cPanel API 1 functions return HTML output, this method will cause parsing errors in most XML parsers. We strongly recommend that you use cPanel API 2 instead.

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