Display affiliates of a private campaign via API

The following sample code shows how to display the list of affiliates invited to a particular private campaign.
//the PapApi.class.php can be downloaded from the merchant panel:
//Tools > Integration > API Integratoin > Download PAP API
include_once 'PapApi.class.php';  

//campaign ID of the particular private campaign
$campaignID = '9e394454'; 

$session = new Pap_Api_Session("http://URL_TO_PAP/scripts/server.php");

if(!@$session->login("merchant@login.com","merchantPassword")) {
  die("Cannot login. Message: ". $session->getMessage());

$request = new Gpf_Rpc_GridRequest("Pap_Features_Common_AffiliateGroupGrid", "getRows", $session);
// sets limit to 30 rows, offset to 0 (first row starts)
$request->setLimit(0, 30);

//you can use general search

// send request
try {
} 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();

//to see what fields are avaiable, uncomment the line below


$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();

$cycles = ceil($totalRecords / $maxRecords);
for($i=1; $i<$cycles; $i++) {
  // now get next 30 records
  $request->setLimit($i * $maxRecords, $maxRecords);
  $recordset = $request->getGrid()->getRecordset();

function iterate($recordset,$session) {
  // iterate through the records
  foreach($recordset as $rec) {
	switch ($status){
	case 'A':
		$status = "Approved";
	case 'P':
		$status = "Pending";
	case 'A':
		$status = "Declined";
    echo $rec->get('firstname'). ' '.$rec->get('lastname').' - '.$rec->get('username').' , Status: '.$status.', Date Added: '.$rec->get('dateadded').'<br>';