Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Excerpt

cPanel API 1 accesses information from the cPanel interface.

Include Page
LIB:_cPanelAPI1Deprecated
LIB:_cPanelAPI1Deprecated

Multiexcerpt include
SpaceWithExcerptcom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@12665
MultiExcerptNameServerProfilesDisabledAPI
PageWithExcerptLIB:_ServerProfilesDisabledAPI

Note
titleNote:

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

Multiexcerpt
MultiExcerptNameBasicUsage


Localtab Group


Localtab
activetrue
titleLiveAPI PHP Class


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

Include Page
LIB:_LiveAPIPHPLink
LIB:_LiveAPIPHPLink


Localtab
titleLiveAPI Perl Module


Code Block
languageperl
linenumberstrue
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.

Include Page
LIB:_LiveAPIPerlLink
LIB:_LiveAPIPerlLink


Localtab
titleTemplate Toolkit


Note
titleNote:

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


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

Include Page
LIB:_TTLink
LIB:_TTLink


Localtab
titlecPanel Tag System (deprecated)

Include Page
LIB:_cPanelTagsWarning
LIB:_cPanelTagsWarning

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



Localtab
titleCommand Line


Code Block
languagetext
cpapi1 --user=username --output=type Module function parameter=value parameter=value


Note
titleNote:

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.

Note
titleNote:

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

Code Block
/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.
    Multiexcerpt include
    MultiExcerptNameShort Macro
    PageWithExcerptLIB:_XMLDeprecated
  • Use --output=yaml to return YAML-formatted output.
Note
titleNote:

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"}'

Include Page
LIB:_BooleanNote
LIB:_BooleanNote


Note
titleNote:

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

Code Block
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.

Warning
titleImportant:
  • 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.

Include Page
LIB:_BooleanNote
LIB:_BooleanNote

example.com

Include Page
LIB:_PageURLWarning
LIB:_PageURLWarning

Call cPanel API 1 from the WHM API

Warning
titleWarning:

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.

Warning
titleImportant:

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.

Anchor
APIMethod
APIMethod
API method distinctions

Multiexcerpt include
MultiExcerptNameAPIExamples
PageWithExcerptGuide to Testing Custom Code