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 500 rows, maximum which can be retrieved in one call
$request->setLimit(0, 500);

// execute request in a loop to load all data
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();
// if you are interested in getting the total number of records matching your filter you can use $request->getGrid()->getTotalCount()
// 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>';
}
} while ($recordset->getSize() == $request->getLimit()); ?>
 
×