This sample script shows the same result as the Campaigns > Affiliates in campaigns grid in the merchant panel.
More exactly, it lists the affiliates and names of private (public with manual approval) campaigns the affiliates belong to.
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 file can be downloaded from the merchant panel at:
// Tools > Integration > API Integration > Download PAP API
// This include assumes the PapApi.class.php file is in the same directory as this particular script.
include 'PapApi.class.php';
$papURL="https://URL_TO_PostAffiliatePro"; //URL to PAP/PAN without trailing slash
$session = new Pap_Api_Session($papURL."/scripts/server.php");
if(!@$session->login("merchant@user.com", "kindOfPassword")) {
die("Cannot login. Message: ".$session->getMessage());
}
$request = new Gpf_Rpc_GridRequest("Pap_Features_Common_AffiliateCampaignsGrid", "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);
//set sorting by campaign name
$request->setSorting("campaignname", "sort_asc");
// 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 'Campaign Name: '.$rec->get('campaignname').' Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
} while ($recordset->getSize() == $request->getLimit());
?>
campaignname,userid,username,firstname,lastname,rstatus,dateadded,note,actions