<?php include 'PapApi.class.php'; //the PapApi.class.php can be downloaded from Tools->Integration->API->Download PapApi.class.php $session = new Pap_Api_Session("https://your_pap_url/scripts/server.php"); if(!$session->login("merchant login","password")) { die("Cannot login. Message: ". $session->getMessage()); } $request = new Gpf_Rpc_GridRequest("Pap_Merchants_Campaign_CampaignsGrid", "getRows", $session); $request->setLimit(0, 100); // sets limit to 100 rows, offset to 0 (first row starts) //you can use general search //$request->addFilter('search', 'L', 'Campaign name'); //sets columns, use it only if you want to retrieve other as default columns //$request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('name'), array('commissionsdetails'), array('rstatus'), array('commissionsexist'), array('account'), array('dateinserted'), array('isdefault'), array('rorder')))); //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($recordset); $totalRecords = $grid->getTotalCount(); $maxRecords = $recordset->getSize(); if ($maxRecords != 0) { $cycles = ceil($totalRecords / $maxRecords); for($i=1; $i<$cycles; $i++) { // now get next 100 records $request->setLimit($i * $maxRecords, $maxRecords); $request->sendNow(); $recordset = $request->getGrid()->getRecordset(); iterate($recordset); } } function iterate($recordset) { // iterate through the records foreach($recordset as $rec) { echo 'Campaign name: ' . $rec->get('name') . ' '. $rec->get('commissionsdetails') . '<br>'; echo 'productID: ' . $rec->get('productid'). '<br>'; echo 'ID: ' . $rec->get('campaignid'). '<br>'; //Uncomment this line to display/obtain also the campaign category name //echo getCampaignCategory($rec->get('campaignid'), $session); } } function getCampaignCategory($campaignid, $session) { $request2 = new Gpf_Rpc_GridRequest("Pap_Features_CampaignsCategories_CampaignInCategoriesGrid", "getRows", $session); $request2->addFilter("campaignid","=",$campaignid); // send request try { $request2->sendNow(); } catch(Exception $e) { die("API call error: ".$e->getMessage()); } // request was successful, get the grid result $grid2 = $request2->getGrid(); // get recordset from the grid $recordset2 = $grid2->getRecordset(); foreach($recordset2 as $rec2) { return $rec2->get('name'); } } ?>
Variables that can be used in the $rec->get() parameter:
campaignid, rtype, rstatus, name, description, dateinserted, rorder, isdefault, networkstatus, logourl (it is the url to campaign image), productid, discontinueurl, validfrom, validto, validnumber, validtype, overwritecookie, accountid, account, accountstatus, commissionsexist, commissionsdetails