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.

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.

<?php
//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("https://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 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);

//you can use general search
$request->addParam('campaignid',$campaignID);

// 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();
  //to see what fields are avaiable, uncomment the line below
  //print_r($recordset);
  iterate($recordset);
} while ($recordset->getSize() == $request->getLimit());

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