Dear customers! We have updated our Privacy Policy. An updated version of the Privacy Policy takes effect on May 25, 2018.

Example: API call results

In the below example, we'll get keywords with the get/keywords_2/keywords/ method.

<?php $libsPath = '/var/www/libs'; // server path to the library folder use TopvisorSDK\V2 as TV; // presumably SDK is in the libs folder include($libsPath.'/topvisor/v2/topvisor.php'); $projectId = '%NN%'; // your project ID // creating a session $Session = new TV\Session(); // initiating a call $selectorKeywords = new TV\Pen($Session, 'get', 'keywords_2', 'keywords'); // setting the project_id parameter $selectorKeywords->setData(['project_id' => $projectId]); // request to get a keyword id and name $selectorKeywords->setFields(['id', 'name']); // filter keywords with 1, 2 or 3 tags $selectorKeywords->setFilters([ TV\Fields::genFilterData('tags', 'IN', [1,2,3]) ]); // sort keywords alphabetically $selectorKeywords->serOrders([ TV\Fields::genOrderData('name', 'ASC') ]); // get 1,000 keywords in one API call $selectorKeywords->setLimit(1000); do{ // processing request (display results page) $page = $selectorKeywords->exec(); // processing error if(is_null($page->getResult())) return var_dump($page->getErrors()); // $page - array of keywords foreach($page->getResult() as $resultItem){ echo $resultItem->id.': '.$resultItem->name.'<br>'; } // find missing keywords // (if this is the last page, $nextOffset is equal to NULL) $nextOffset = $page->getNextOffset(); if($nextOffset) $selectorKeywords->setOffset($nextOffset); // keep on retrieving keywords until all pages retrieved }while($nextOffset);