Page tree
Skip to end of metadata
Go to start of metadata

 

Introduction

You can use special variables to select the parameters to display in cPanel API 2 output.

Notes:

  • cPanel & WHM introduced this feature in version 11.48.
  • You can test cPanel API 2 functions with column selection in cPanel's API Shell interface (Home >> Advanced >> API Shell). Click Show paginate/Filter/Paginate Options to display column selection options.

Column selection variables

cPanel API 2 column selection uses two basic variables:

VariableTypeDescriptionPossible values
api2_columnsBooleanWhether to enable columns.
  • 1 — Enable columns.
  • 0 — Disable columns.
api2_columns_astringThe parameter that you wish to display.

A valid parameter name for the function.

To output multiple columns on a single cPanel API 2 call, add another string variable that uses the next letter in the alphabet (For example, api2_columns_b, api2_columns_c, api2_columns_d.)

Examples

The following example displays the ip and timestamp parameter results for the  Stats::lastvisitors  function.

/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_user=user&cpanel_xmlapi_module=Stats&cpanel_xmlapi_func=lastvisitors&domain=example.com&api2_sort=1&api2_columns_a=ip&api2_columns_b=timestamp&api2_columns=1

 

Note:

 For more information, read our Calls from the WHM API documentation.

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Call the listvisitors function and display only ip and timestamp.
$limited_visitors = $cpanel->api2(
    'Stats', 'lastvisitors', 
    array(
        'domain'                     => 'example.com',
        'api2_columns'               => '1',
        'api2_columns_a'             => 'ip',
        'api2_columns_b'             => 'timestamp',
    ) 
);

Note:

For more information, read our Guide to the LiveAPI System.

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.

# Call the listvisitors function and display only ip and timestamp.
my $limited_visitors = $cpliveapi->api2(
    'Stats', 'lastvisitors',
    { 
        'domain'                     => 'example.com',
        'api2_columns'               => '1',
        'api2_columns_a'             => 'ip',
        'api2_columns_b'             => 'timestamp',
    }
);

Note:

For more information, read our Guide to the LiveAPI System.

cpapi2 --user=username Stats lastvisitors api2_columns=1 api2_columns_a=ip api2_columns_b=timestamp
<?cp Email::listpopswithdisk (
          %[br],
          ip
          )
          domain="example.com",
          api2_columns="1",
          api2_columns_a="ip",
          api2_columns_b="timestamp",
?> 

 

Warning:

In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs.

cPanel API 2 calls that use cPanel tags vary widely in code syntax and in their output. For more information, read our Deprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.