The following example shows how to obtain the list of Raw Clicks via API.
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. Details are described in the Gpf_Rpc_GridRequest article.
<?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
// the first parameter is an offset which is not used, always keep it at 0
$request->setLimit(0, 500);
// 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();
// 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('lastname').' | Campaign: '.$rec->get('campaign').' | Banner: '.$rec->get('banner').'<br>';
}
} while ($recordset->getSize() == $request->getLimit());
?>