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.
//----------------------------------------------
// 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 limit to 30 rows, offset to 0 (first row starts)
$request->setLimit(0, 30);
// 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'))));
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die("API call error: ".$e->getMessage());
}
// request was successful, get the grid result
$grid = $request->getGrid();
// get recordset from the grid
$recordset = $grid->getRecordset();
// iterate through the records
foreach($recordset as $rec) {
echo 'Affiliate userid: '.$rec->get('userid').', Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
//----------------------------------------------
// in case there are more than 30 records in total,
// we should load and display the rest of the records
// via the cycle below
while ($recordset->getSize() == $request->getLimit()) {
$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>';
}
}
Example of paging in older versions than 5.11.8.1
//----------------------------------------------
// loading next rows/paging in old versions
$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();
if ($maxRecords != 0) {
$cycles = ceil($totalRecords / $maxRecords);
for($i=1; $i<$cycles; $i++) {
// now get next 30 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>';
}
}
}
NOTE: do not forget to login as merchant via API