Grid object - this class handles requests to the list of affiliates. You can use it to search and filter in affiliates.
Methods:
-
all methods are inherited from Gpf_Rpc_GridRequest class, check it's documentation.
Note: The first parameter of setLimit() is an offset that is no longer used since version 5.11.8.1 — always pass 0. Paging is handled automatically: sending the same request object again returns the next page of records. The maximum number of records returned in one request is 500. Use the largest page size your script can handle, as it means fewer API calls. Details are described in the Gpf_Rpc_GridRequest article.
Example retrieving list of all affiliates
//----------------------------------------------
// get recordset with list of affiliates
$request = new Pap_Api_AffiliatesGrid($session);
//Filtering affiliate with username affiliate@example.com - Filters are not mandatory
$request->addFilter('username', Gpf_Data_Filter::EQUALS, 'affiliate@example.com');
// sets the page size to 500 rows, which is the maximum per request
// the first parameter is an offset which is not used, always keep it at 0
$request->setLimit(0, 500);
// sets columns, use it only if you want retrieve other as default columns
$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('refid'), array('userid'),
array('username'), array('firstname'), array('lastname'), array('rstatus'), array('parentuserid'),
array('dateinserted'), array('salesCount'), array('clicksRaw'), array('clicksUnique'))));
// execute request in a loop to load all data
// sending the same request again returns the next page
do {
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die("API call error: ".$e->getMessage());
}
// request was successful, get the grid result and its recordset
$recordset = $request->getGrid()->getRecordset();
// iterate through the records
foreach($recordset as $rec) {
echo 'Affiliate userid: '.$rec->get('userid').', Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
} while ($recordset->getSize() == $request->getLimit());
Example of paging in older versions than 5.11.8.1
Important: The example below is kept for reference only. Do not use it on version 5.11.8.1 and newer. If your script sends an offset, the request fails with the error API: Using "offset" in grid requests is not allowed. To resolve it, download a new PapApi.class.php file in the merchant panel at Tools > Integration > API Integration > Download PAP API and use the paging shown in the first example.
//----------------------------------------------
// loading next rows/paging in old versions
$request->sendNow();
$grid = $request->getGrid();
$recordset = $grid->getRecordset();
$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();
if ($maxRecords != 0) {
$cycles = ceil($totalRecords / $maxRecords);
for($i=1; $i<$cycles; $i++) {
// now get the next page of records
$request->setLimit($i * $maxRecords, $maxRecords);
$request->sendNow();
$recordset = $request->getGrid()->getRecordset();
// iterate through the records
foreach($recordset as $rec) {
echo 'Affiliate userid: '.$rec->get('userid').', Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
}
}