Get the list of Raw Clicks

The following example shows how to obtain the list of Raw Clicks via API.
 
<?php
// PapApi.class.php can be downloaded from the merchant panel at Tools > Integration > API Integration
include '../pap/api/PapApi.class.php';

$papURL="https://URL_TO_PAP"; //URL leading to PAP/PAN without trailing slash
$merchantUsername = "merchant@user.com";
$merchantPassword = "merchantpassword";

//------------------------------------------------------------------
// login (as merchant)
$session = new Pap_Api_Session($papURL."/scripts/server.php"); 
if(!@$session->login($merchantUsername, $merchantPassword)) {
  die("Cannot login. Message: ".$session->getMessage());
}

//------------------------------------------------------------------
// get recordset with list of clicks
$request = new Gpf_Rpc_Gridrequest("Pap_Merchants_Reports_ClicksGrid","getRows",$session);

//available columns
//id,userid,username,firstname,lastname,banner,campaign,countrycode,rtype,datetime,referrerurl,ip,cdata1,cdata2
$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'),array('banner'),array('firstname'), array('lastname'), array('campaign'),  array('datetime'))));

// SET FILTER 
$request->addFilter("datetime","D>=","2013-02-19");
$request->addFilter("datetime","D<=","2013-02-22");
$request->addFilter('campaignid','=','dea29621');

//Filter Only Raw and Declined clicks. R - raw, D - declined, U - unique 
$request->addFilter('rtype','IN','R,D');  
// sets limit to 30 rows, offset to 0 (first row starts)
$request->setLimit(0, 30);

// 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();
echo "Total number of records: ".$grid->getTotalCount()."<br>";

// iterate through the records
foreach($recordset as $rec) {
  echo 'ID: '.$rec->get('id').' | Affiliate: '.$rec->get('firstname')." ".$rec->get('firstname').' | Campaign: '.$rec->get('campaign').' | Banner: '.$rec->get('banner').'<br>';
}

//------------------------------------------------------------------
//in case there were more than 30 records, let's load them in cycles
$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 'ID: '.$rec->get('id').' | Affiliate: '.$rec->get('firstname')." ".$rec->get('firstname').' | Campaign: '.$rec->get('campaign').' | Banner: '.$rec->get('banner').'<br>';
		}	  
	}
}


?>
 
×