The following code shows, how you can load valid and assigned coupons via php 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 //your PapApi.class.php file can be downloaded in the merchant panel at: //Tools>Integration>API Integration>Download PAP API //this include below assumes the PapApi.class.php is in the same dir as this script include ("PapApi.class.php"); //change localhost/pap to the path of your Post Affiliate Pro installation $session = new Pap_Api_Session("https://localhost/pap/scripts/server.php"); //login as merchant (in PAN as Network-Owner) using merchant panel login credentials if(!$session->login("merchant@example.com","demo")) { die("Cannot login. Message: ". $session->getMessage()); } $request = new Gpf_Rpc_GridRequest("Pap_Features_Coupon_CouponsGrid", "getRows", $session); //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); //9abc240b is the ID of the coupon banner at Banners > Banners manager. //If the ID is not displayed, enable it in the "Edit View" section. $request->addFilter("bannerid", Gpf_Data_Filter::EQUALS, '9abc240b'); $todayDate = date("Y-m-d"); // 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(); // iterate through the records foreach($recordset as $rec) { $ValidFromDate = $rec->get('validfrom'); $from = explode(" ",$ValidFromDate); $ValidToDate = $rec->get('validto'); $to = explode(" ", $ValidToDate ?? ''); //load only approved and valid coupons which are assigned to some affiliate and are not used up if ((($rec->get('userid'))!= NULL) && (($rec->get('rstatus'))=='A') && ($from[0]<=$todayDate) && ($to[0] == '' || $to[0]>=$todayDate) && ($rec->get('limit_use') == '0' || ($rec->get('usecount')<$rec->get('limit_use')))) { //print_r($rec); //here you can get a list of all of the available data. echo '<br> Coupon code: '.$rec->get('couponcode').' Name: ' .$rec->get('firstname') . ' ' .$rec->get('lastname') . ' refid: ' .$rec->get('refid') . '<br>'; } } } while ($recordset->getSize() == $request->getLimit()); ?>