1. How do I get list of all banners?

With use of Gpf_Rpc_GridRequest you can use this code to get all banners from your merchant panel:

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.

include 'path/to/your/api/file/PapApi.class.php';

$session = new Pap_Api_Session("https://localhost/scripts/server.php"); //replace https://localhost/scripts with link to your PAP installation URL
if(!$session->login("merchant_name", "merchant_password")) {
  die('Failed authentication');
}

$request = new Gpf_Rpc_GridRequest("Pap_Merchants_Banner_BannersGrid", "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);

// 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) {
		echo 'Banner name: '.$rec->get('name').'<br>';
	}
} while ($recordset->getSize() == $request->getLimit());

Example of paging for older versions than 5.11.8.1

Important: The example below is kept for reference only. Do not use it on version 5.11.8.1 and newer. If your script sends an offset, the request fails with the error API: Using "offset" in grid requests is not allowed. To resolve it, download a new PapApi.class.php file in the merchant panel at Tools > Integration > API Integration > Download PAP API and use the paging shown in the first example.

include 'path/to/your/api/file/PapApi.class.php';

$session = new Pap_Api_Session("https://localhost/scripts/server.php"); //replace https://localhost/scripts with link to your PAP installation URL
if(!$session->login("merchant_name", "merchant_password")) {
  die('Failed authentication');
}

$request = new Gpf_Rpc_GridRequest("Pap_Merchants_Banner_BannersGrid", "getRows", $session);
$request->setLimit(0, 30); //get me only first 30 banners

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 through the records
foreach($recordset as $rec) {
  echo 'Banner name: '.$rec->get('name').'<br>';
}


// In case there were more than 30 records, let's get the rest of them in cycles
$totalRecords = $grid->getTotalCount();
$maxRecords = $recordset->getSize();
if ($maxRecords != 0) {
	$cycles = ceil($totalRecords / $maxRecords);
	for($i=1; $i<$cycles; $i++) {
		// now get next 30 records
		$request->setLimit($i * $maxRecords, $maxRecords);
		$request->sendNow();
		$recordset = $request->getGrid()->getRecordset();
		// iterate through the records
		foreach($recordset as $rec) {
			echo 'Banner name: '.$rec->get('name').'<br>';
		}		  
	}
}
 
Optionally you can get additional fields from $rec like:
  • bannerid
  • accountid
  • campaignid
  • campaignname
  • rtype
  • rstatus
  • name
  • destinationurl
  • dateinserted
  • size
  • data1-data9
  • rorder
  • ctype
  • wrapperid
  • description
  • seostring