Load the whole Campaigns Categories tree

This is a sample code of how to load all Campaigns Categories:

$papURL = "https://URL_TO_PostAffiliatePro"; //URL of your Post Affiliate Pro installation without any trailing slash
$merchantUsername = "merchant@example.com"; //merchant username
$merchantPassword = "123456"; //merchant password

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

$session = new Pap_Api_Session($papURL."/scripts/server.php");   

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

$request = new Gpf_Rpc_Request('Pap_Features_CampaignsCategories_TreePanel', 'loadTree', $session);

//$request->addParam("addDetails", "Y"); // use this only if you want to load also all campaign IDs in categories

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

$response = $request->getStdResponse();

$categories = json_decode($response[1][1]);

foreach ($categories as $category) {

function displayCategoryItem($category, $parentCategoryCode = null) {
    echo '<br>code: '.$category->data->code;
    if ($parentCategoryCode != null) {
        echo ' (parent category: '.$parentCategoryCode.') ';
    echo ', name: '.$category->data->name;
    //echo ', campaignids: '.$category->data->campaignids; //available only with parameter 'addDetails'
    foreach ($category->items as $item) {
        displayCategoryItem($item, $category->data->code);