Configuring campaign commissions via API

After you add a campaign via API it is essential to configure its commissions. 

Here is a sample script how to configure a campaign's commission structure (the default commission group) -- Sale or Click commission. 

If you wish to add an action commission to a campaign via API then check the notes below this sample code or click here.

//your PapApi.class.php file can be downloaded in the merchant panel: Tools>Integration>API Integration>Download PAP API
include '../pap/api/PapApi.class.php';

$papUrl = ""; //URL leading to your Post Affiliate Pro
$merchantUsername = ""; //merchant username
$merchantPassword = "demo"; //merchant password
$campaignID = "c6fce328"; //Campaign ID of the campaign you wish to configure it's commissions
$commissionType = 'S'; //S = "per Sale" commission type,  C = "per Click" commission type

$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_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "save", $session);

//ID of the particular commissoin group -- MANDATORY
//how to find out 'commission group id' via API:
$request->setField("CommissionGroupId",getDefaultCommissionGroupID($campaignID, $session));

//ID of the per Sale or per Click commission type.  -- MANDATORY
$request->setField("Id",getCommissionTypeID($campaignID, $commissionType, $session));

//Status of the commission. --Mandatory
// "E" = enabled. "D" = disabled. 

//Type of commission -- MANDATORY
//"S" = sale, "C" = click

//Leave it blank -- MANDATORY

//Approval -- MANDATORY. "A" = automatic, "M" - manual

//Save transaction also for zero orders (Total Cost = 0) -- MANDATORY
//default value "N".  In order to allow that option, use "Y" instead of "N". 

//Save transaction with zero commission -- MANDATORY
//default value "N".  In order to allow that option, use "Y" instead of "N". 

//use fixed cost -- MANDATORY
//default value "N" - not to use FixedCost

// Type of fixed cost: "%" or "$" -- Mandatory if the previous field uses "Y" instead of "N"
// numeric value of fixed cost -- MANDATORY

//Type of Default (1st tier) commission -- MANDATORY

//Value of Default (1st tier) commission -- MANDATORY

//N_X_  while X represents the tier
// Value of 2nd tier commission

//Period of recurrence: 
//"varied" -> more info here:
//"each15m" = each 15 minutesus, "A" = Daily, "B" = Weekly, "C", Monthly, "Q" = Quaterly, "D" = Semianually, "E" = yearly

//Type of 1st tier recurring commission -- Mandatory if the previous field is set

//Value of 1st tier recurring commission -- Mandatory if the previous field is set

// If you wish to define more tiers of recurring commissions, then use R_X_ while X represents the corresponding tier 

try  {
// Send the request to PAP
} catch(Exception $e){
die("API call error: " . $e->getMessage());

// Get the response as normal array
$response = $request->getStdResponse();

echo $response->message;

function getDefaultCommissionGroupID($campaignID, $session) {  
	$request = new Gpf_Rpc_Request("Pap_Merchants_Campaign_CommissionGroups","loadCommissionGroups",$session);
	// Set the campaign id for which we want the commission group

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

	$response = $request->getStdResponse();
	$groupName = 'Default commission group';

	foreach ($response as $resp) {
	  if ($resp[1] == $groupName ) {
		  return $resp[0];

function getCommissionTypeID($campaignID, $commissionType, $session) {
	$request = new Gpf_Rpc_Request("Pap_Merchants_Campaign_Commissions", "loadCommissionTypes", $session);
	$request->addParam('campaignid', $campaignID);

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

	// request was successful, get the rows
	$result = $request->getStdResponse();

	$rtypeKey = array_search('rtype', $result[0]); 
	$commtypeidKey = array_search('commtypeid', $result[0]);

	// find certain commissiontypeid by commissiontype
	foreach ($result as $row) {
	  if ($row[$rtypeKey] == $commissionType) {
		$commtypeid = $row[$commtypeidKey];
	return $commtypeid;

That's it. 

Configuring an action commission

In order to add an action commission, the following changes have to be applied in the above given sample code:
1) In
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "save", $session);
you have to use "add" instead of "save".
So the changed row will result in:
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "add", $session);
2) Use $commissionType = 'A'; 
So instead of "S" or "C" the value is "A".
Also, right after the line of  $commissionType = 'A'; 
define (add) the following:
$actionCode = 'something';  // code of action commission
$actionName = 'something else'; // name of action commission
where of course you set the desired  code and name of action commission.
3) In the code instead of
$request->setField("Id",getCommissionTypeID($campaignID, $commissionType, $session));
4) Finally right after the code of 
add the following block of code:
if ($commissionType == 'A') {
That's it.