The following sample script shows how to get the Top Affiliates report data 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. Use the largest page size your script can handle, as it means fewer API calls. Details are described in the Gpf_Rpc_GridRequest article.
<?php // the PapApi.class.php file can be downloaded from the merchant panel at: // Tools > Integration > API Integration > Download PAP API // This include assumes the PapApi.class.php file is in the same directory as this particular script. include 'PapApi.class.php'; $papURL = "https://URL_TO_PostAffiliatePro"; //URL to Post Affiliate Pro without any trailing slash $merchantUsername = "merchant@username.com"; //merchant username $merchantPassword = "123456"; //---------------------------------------------- // login (as merchant) // change localhost/pap to the real URL leading to your installation of Post Affiliate Pro $session = new Pap_Api_Session($papURL."/scripts/server.php"); //$session->setDebug(); if(!@$session->login($merchantUsername, $merchantPassword)) { exit("Cannot login. Message: ".$session->getMessage()); } //---------------------------------------------- // get the list of Top Affiliates records $request = new Gpf_Rpc_GridRequest("Pap_Merchants_User_TopAffiliatesGrid","getRows",$session); //add support of additional columns for the php API $request->addParam('columns', new Gpf_Rpc_Array(array(array('id'), array('userid'), array('username'), array('firstname'), array('lastname'), array('clicksRaw'), array('salesCount')))); //to see all available parameters, check the following article: // https://support.qualityunit.com/775501-Debugging-with-Firefox // sets the page size to 500 rows, which is the maximum per request // the first parameter is an offset which is not used, always keep it at 0 $request->setLimit(0, 500); //filtering stats only for the last (previous) month $request->addFilter("statsdaterange",Gpf_Data_Filter::DATERANGE_IS,Gpf_Data_Filter::RANGE_LAST_MONTH); //more info on date/time range options: https://support.qualityunit.com/233666-Gpf_Rpc_GridRequest //sorting based on sales count $request->setSorting('salesCount', false); //true = Ascending; false = Descending // 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) { exit("API call error: ".$e->getMessage()); } // request was successful, get the grid result and its recordset $recordset = $request->getGrid()->getRecordset(); // iterate through the records foreach($recordset as $rec) { echo 'Affiliate: '.$rec->get('firstname').' '.$rec->get('lastname').' ('.$rec->get('username').'), Raw clicks: '.$rec->get('clicksRaw').', Sales Count: '.$rec->get('salesCount')."<br>"; } } while ($recordset->getSize() == $request->getLimit()); ?>