How to load channel stats for affiliate

If you want to load channel stats report for affiliate, you can send a grid request to class Pap_Affiliates_Reports_ChannelStatsGrid. Notice that you need to use affiliate login details for API login because the channel stats report is from the affiliate panel.
 
<?php
include 'PapApi.class.php'; //the PapApi.class.php can be found under Tools->Integration->API integration
$session = new Pap_Api_Session("https://URL_to_PAP/scripts/server.php");
if(!$session->login("affiliate@username.com","affiliatepassword", Pap_Api_Session::AFFILIATE)) {
    die("Cannot login. Message: ". $session->getMessage());
}
$request = new Gpf_Rpc_GridRequest("Pap_Affiliates_Reports_ChannelStatsGrid", "getRows", $session);
//columns which you want to load
$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('channel'), array('impressionsRaw'), array('impressionsUnique'), array('clicksRaw'), array('ctrRaw'), array('clicksUnique'), array('ctrUnique'), array('salesCount'), array('salesTotal'), array('commissions'))));
//Filter a certain date range
$request->addFilter("datetime","D>=","2018-01-04"); //date from
$request->addFilter("datetime","D<=","2018-03-05"); //date to
// 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 'Name: '.$rec->get('channel').' impressionsRaw: '.$rec->get('impressionsRaw').' impressionsUnique: '.$rec->get('impressionsUnique').' clicksRaw: '.$rec->get('clicksRaw').' ctrRaw: '.$rec->get('ctrRaw').' clicksUnique: '.$rec->get('clicksUnique').' ctrUnique: '.$rec->get('ctrUnique').' salesCount: '.$rec->get('salesCount').' salesTotal: '.$rec->get('salesTotal').' commissions: '.$rec->get('commissions').'<br>';
}
?>
×