Add (or remove) a banner to Banner Categories

You can use the following code to add (or remove) a specific banner to Banner Categories. You'll need to know the IDs of the categories to which you want to add the banner or remove it from, you can get these IDs by loading all the categories as explained here.

To add a banner to a category you must set the category's "selected" attribute to Y and to remove you must set "selected" to N. This is essentially a patch request so you don't need to list all current categories, you'd list only the categories which you want to change somehow.
 

<?php
$papURL = "https://SOMETHING.postaffiliatepro.com/scripts/server.php"; // replace with your Post Affiliate Pro URL address
$merchantUsername = "merchant@username.com";
$merchantPassword = "password";

//your PapApi.class.php file can be downloaded in the merchant panel:
//Tools>Integration>API Integration>Download PAP API
require "PapApi.class.php"; //this include assumes the PapApi.class.php is in the same dir as this script

$session = new Pap_Api_Session($papURL);   

//login as merchant
if(!@$session->login($merchantUsername, $merchantPassword)) {
    die ("Cannot login. Message: ".$session->getMessage());
}

$request = new Gpf_Rpc_Request('Pap_Features_BannersCategories_EditableCategoriesGrid', 'saveCategories', $session);
$request->addParam('bannerid', '5ec43fb4'); // enter ID of the banner you wish to change categories for
$request->addParam('fields', new Gpf_Rpc_Array(array(
    array('id', 'name', 'value'),
    array('3', 'selected', 'Y'), // set the ID / code of the category to which the banner should belong, you can use this approach to load all existing categories https://support.qualityunit.com/184520-Load-the-whole-Banners-Categories-tree
    array('5','selected', 'Y')))); // selected is set to Y when you want to add banner to this category and to N when you want to remove the banner from this category

try {
    $request->sendNow();
}
catch(Exception $e) {
    die("API call error: ".$e->getMessage());
}

$response = $request->getStdResponse();
if ($response->success == 'Y') {
    echo 'Successful: ' . $response->infoMessage;
}
else {
    echo 'Unsuccessful: ' . $response->errorMessage;
}
?>
×