Paginated selection (limit and offset)

These results are applicable to read-only operations, i.e. to use with the get operator

Results of API selection are called a results page.
Every page can include up to 10 000 results.
Page size can be managed with the limit parameter which is set to 10 000 results by default.
The number of results to skip on the results page can be changed with the offset parameter.

If some results are missing in the selection, the result will include additional parameters:

  • nextOffset - offset value for the next page selection
  • total - total results count

Examples

We'll get a selection limited to 25 results.
We want to get all results with the page limit set to 10 results per page.

Request


{"limit":10, "offset":0}

Result


			{"result":[ /* first 10 results */ ],"nextOffset":10,"total":25}
			

Request


{"limit":10, "offset":10}

Result


			{"result":[ /* Results from 11 to 20 */ ],"nextOffset":20,"total":25}
			

Request


{"limit":10, "offset":20}

Result


			{
				"result":[ /* Results from 21 to 25 */ ],
				"total":25
				// please note that this is the last page, so nextOffset won't be returned
			}
			

SDK example

In the below example, we'll get a list of keywords of the %NN% project:

	<?php

	$projectId = '%NN%'; // ID of your project
	$limit = 10; // page size

	$TVSession = new TVSession();

	$selectorKeywords = new TVPen($TVSession, 'get', 'keywords_2', 'keywords');
	$selectorKeywords->setData(['project_id' => $projectId]);
	$selectorKeywords->setLimit($limit);

	// get all result pages
	do{
		$page = $selectorKeywords->exec();
		if(is_null($page->getResult())) return var_dump($page->getErrors());

		// $page - array of keywords
		foreach($page->getResult() as $resultItem){
			var_dump($resultItem);
		}

		$nextOffset = $page->getNextOffset();
		if($nextOffset) $selectorKeywords->setOffset($nextOffset);
	}while($nextOffset);