Get (retrieve) banner codes via API (only for affiliates)

If some affiliates wish to obtain their banner codes via API so that they add all their banners to their page(s) dynamically and the fastest way possible, then the following php API example will come in handy.
define('URL_TO_PAP','https://URL_To_PostAffiliatePro'); //URL to Post Affiliate Pro (network) without any trailing slash
define('AFFILIATE_USERNAME',''); //affiliate username
define('AFFILIATE_PASSWORD','demo'); //affiliate password
//the PapApi.class.php file can be downloaded in the merchant panel: Tools>Integration>API Integration>Download PAP API
//make sure the PapApi.class.php file is uploaded in the same directory as this script itself.

$session = papAffiliateLogin();
if (!$session){
    die('Banner codes cannot be obtained due to failed login attempt');

$bannerCodes = getBannerCodes($session); //obtaining the banner codes as a genric HTML code that is directly executed
$bannerCodesNeatCode = getBannerCodes($session,'Y'); //utlizing
if ($bannerCodes) {
foreach ($bannerCodes as $code){
    echo $code."<hr>";
if ($bannerCodesNeatCode) {
foreach ($bannerCodesNeatCode as $code){
    echo $code."<hr>";

/*definition of functions to be used*/
function papAffiliateLogin(){
    try {
        include_once API_FILE;
        $session = new Pap_Api_Session(URL_TO_PAP."/scripts/server.php"); 
        if(!$session->login(AFFILIATE_USERNAME, AFFILIATE_PASSWORD, Gpf_Api_Session::AFFILIATE)) { //change it here for affiliate username and password
            die("Cannot login. Message: ".$session->getMessage());
        return $session;
    } catch (Exception $e){
        die('Error: '.$e->getMessage());        

function getBannerCodes($session,$htmlSpecialChars=NULL){
    $bannerCodes = array();
    // get recordset with list of banners
    $request = new Gpf_Rpc_Gridrequest("Pap_Affiliates_Promo_BannersGrid","getRows",$session);
    // sets limit to 30 rows, offset to 0 (first row starts)
    $request->setLimit(0, 30);
    // Filter particular banner type(s); A = link banner, E =  promo email, F = flash, H = HTML, I = image, V = Simple PDF, T = Text-Link
    //$request->addFilter('id',Gpf_Data_Filter::EQUALS,'11110001');  // use this for filtering exact banner ID
    // send request in a loop to load all records
    do {
        try {
        } 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 and fill in the results array
        foreach($recordset as $rec) {                    
            if(isset($htmlSpecialChars) && $htmlSpecialChars == 'Y'){
                $bannerCodes[] = htmlspecialchars($rec->get('bannercode'));
            } else {
                $bannerCodes[] = $rec->get('bannercode');
    } while ($recordset->getSize() == $request->getLimit());
    return $bannerCodes;