cPanel API 2 - Paginate Output
The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.
Introduction
You can use special variables to display cPanel API 2 output data in multiple pages (pagination). When you use pagination, the function's output's metadata includes the following hash of pagination control information:
paginate":{
"total_pages":1,
"total_results":1,
"current_page":1,
"results_per_page":100,
"start_result":"1"
}
You can test cPanel API 2 functions with pagination in cPanel's API Shell interface (Home >> Advanced >> API Shell). Click Show paginate/Filter/Paginate Options to display pagination options.
Pagination variables
cPanel API 2 pagination uses four basic variables:
Variable | Type | Description | Possible values |
---|---|---|---|
api2_paginate |
Boolean | Whether to enable pagination. |
|
api2_paginate_start |
integer | The first record to display. | An integer value that represents a number of records. For example, begin the page's list of records with the fifth record, pass in an api2_paginate_start value of 5 . |
api2_paginate_size |
integer | The number of records to display. | An integer value that represents a number of records. For example, to display ten records on the page, pass in an api2_paginate_size value of 10 . |
api2_paginate_page |
integer | The page of results to display. | An integer value that represents which page of results to display. For example, to display the second page of records, pass in an api2_paginate_page value of 2 . |
Examples
The following examples display paginated results for the Email::listpopswithdisk
function.
- The example for the first page of results begins at the fifth record, and lists through the fourteenth record, to display a total of 10 records.
- The example for the second page of results begins at the fifteenth record, and lists through the twenty-fourth record, to display a total of 10 records.
WHM API
/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=listpopswithdisk&domain=example.com&api2_paginate_start=5&api2_paginate_size=10&api2_paginate=1
/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=listpopswithdisk&domain=example.com&api2_paginate_start=5&api2_paginate_size=10&api2_paginate_page=2&api2_paginate=1
For more information, read our Use WHM API to Call cPanel API and UAPI documentation.
LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Call the first page of recent visitors.
$paginateed_visitors = $cpanel->api2(
'Stats', 'lastvisitors',
array(
'domain' => 'example.com',
'api2_paginate' => '1',
'api2_paginate_start' => '5',
'api2_paginate_size' => '10',
)
);
// Call the second page of recent visitors.
$paginateed_visitors = $cpanel->api2(
'Stats', 'lastvisitors',
array(
'domain' => 'example.com',
'api2_paginate' => '1',
'api2_paginate_start' => '5',
'api2_paginate_size' => '10',
'api2_paginate_page' => '2',
)
);
For more information, read our Guide to LiveAPI System documentation.
LiveAPI Perl Class
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Call the first page of visitors.
my $paginated_visitors = $cpliveapi->api2(
'Stats', 'lastvisitors',
{
'domain' => 'example.com',
'api2_paginate' => '1',
'api2_paginate_start' => '5',
'api2_paginate_size' => '10',
}
);
# Call the second page of visitors.
my $paginated_visitors = $cpliveapi->api2(
'Stats', 'lastvisitors',
{
'domain' => 'example.com',
'api2_paginate' => '1',
'api2_paginate_start' => '5',
'api2_paginate_size' => '10',
'api2_paginate_page' => '2',
}
);
For more information, read our Guide to LiveAPI System documentation.
Command Line
cpapi2 --user=username Stats lastvisitors api2_paginate=1 api2_pagiante_start=5 api2_paginate_size=10
cpapi2 --user=username Stats lastvisitors api2_paginate=1 api2_pagiante_start=5 api2_paginate_size=10 api2_paginate_page=5
cPanel Tag System (deprecated)
<?cp Email::listpopswithdisk (
%[br],
ip
)
domain="example.com",
api2_paginate="1",
api2_paginate_start="5",
api2_paginate_size="10",
<?cp Email::listpopswithdisk (
%[br],
ip
)
domain="example.com",
api2_paginate="1",
api2_paginate_start="5",
api2_paginate_size="10",
api2_paginate_page="2",
?>
- cPanel tags are deprecated . We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI .
- cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
- For more information, read our Deprecated cPanel Tag Usage documentation.