Child pages
  • cPanel API 2 - Paginate Output
Skip to end of metadata
Go to start of metadata

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

Note:

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:

VariableTypeDescriptionPossible values
api2_paginateBooleanWhether to enable pagination.
  • 1 — Enable pagination.
  • 0 — Disable pagination.
api2_paginate_startintegerThe 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_sizeinteger

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_pageintegerThe 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.
/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


Note:

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

$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',
    ) 
);


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 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',
    }
);


Note:

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

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
<?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",
?> 

 


Warnings:

  • 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. 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.