Gpf_Rpc_Request calls method of specified class. With this class you can call almost any class in the Post Affiliate Pro and do almost any action. For grids and forms, use Gpf_Rpc_GridRequest and Gpf_Rpc_FormRequest.

Constructor:
Gpf_RpcRequest($className, $methodName, $session)
$className - name of the class you are calling.
$methodName - name of the method in the class. Use addParam() if you want to pass parameters to the method. 
All available methods can be found out via debugging any request made in the merchant/affiliate panel:
 
In case of `Pap_Merchants_User_AffiliatesGridSimple` the file is in include/Pap/Merchants/User/AffiliatesGridSimple.class.php .
$session - Gpf session object. refer to `Pap_Api_Session` documentation: https://support.qualityunit.com/931835-Pap_Api_Session.

Methods:
setAccountId($accountId) - set merchant's account id. Default is 'default1'.
addParam($name, $value) - set parameter for the method you are calling.
setUrl($url) - set URL for the request if you want to send it to different URL then what is defined in $session.
send() - You can send multiple requests in one call, this method adds current request to the multirequest.
sendNow() - add current request to multirequest and send it to PAP.
setResponseError($message) - set the response error message. This is useful if you are making a subclass of Gpf_Rpc_Request.
getResponseError() - get the response error message.
setResponse($response) - set the response.
getStdResponse() - get the response as PHP array.
getResponseObject() - get the response as Gpf_Rpc_Object object.
setParams(Gpf_Rpc_Params $params) - set parameters for the method using Gpf_Rpc_Params object.

With this request it is possible to call various requests from PAP. Here are some example codes:
 
 
How to obtain number of affiliates in PAP
//include API fileinclude_once 'PapApi.class.php';
//open merchant session
$session = new Pap_Api_Session("path_to_server.php");
if(!$session->login("merchant_name", "pass")) {
  die('Failed authentication');
}
//create request object
$request = new Gpf_Rpc_Request("Pap_Merchants_User_AffiliatesGridSimple", "getRowCount", $session);
// send request
try {
  $request->sendNow();
} catch(Exception $e) {
  die("API call error: ".$e->getMessage());
}
// request was successful, get the rows count value
$answer = $request->getStdResponse()->count;

Adding an affiliate to a private campaign
//include API file
include_once 'PapApi.class.php';

//open merchant session
$session = new Pap_Api_Session("path_to_server.php");
if(!$session->login("merchant_name", "pass")) {
  die('Failed authentication');
}

$request = new Gpf_Rpc_Request('Pap_Db_UserInCommissionGroup', 'addUsers', $session);
$request->addParam('sendNotification', 'N');
$request->addParam('campaignId', '11111111');
$request->addParam('ids', new Gpf_Rpc_Array(array('11111111'))); // ID of affiliate(s) to be moved into the private campaign

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;
}
×