Child pages
  • cPanel API 2 - Output Columns

Versions Compared

Key

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

Introduction

Excerpt

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


Note
titleNotes:
  • 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.

Localtab Group


Localtab
activetrue
titleWHM API


Code Block
languagetext
/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

 

Include Page
LIB:_CallFromWHMAPILink
LIB:_CallFromWHMAPILink


Localtab
titleLiveAPI PHP Class


Code Block
languagephp
linenumberstrue
$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',
    ) 
);

Include Page
LIB:_LiveAPIPHPLink
LIB:_LiveAPIPHPLink


Localtab
titleLiveAPI Perl Class


Code Block
languageperl
linenumberstrue
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',
    }
);

Include Page
LIB:_LiveAPIPerlLink
LIB:_LiveAPIPerlLink


Localtab
titleCommand Line


Code Block
cpapi2 --user=username Stats lastvisitors api2_columns=1 api2_columns_a=ip api2_columns_b=timestamp



Localtab
titlecPanel Tag System (deprecated)


Code Block
languagetext
linenumberstrue
<?cp Email::listpopswithdisk (
          %[br],
          ip
          )
          domain="example.com",
          api2_columns="1",
          api2_columns_a="ip",
          api2_columns_b="timestamp",
?> 

 

Include Page
LIB:_cPanelAPI2cPanelTagsWarning
LIB:_cPanelAPI2cPanelTagsWarning