Approve affiliate with API

Following example shows, how you can approve pending affiliate using Post Affiliate Pro API.
 
Include API:
include_once('PapApi.class.php');
Login as merchant to get rights manipulating with Affiliate rows:
$session = new Pap_Api_Session("https://demo.qualityunit.com/pax4/scripts/server.php");
if(!$session->login("merchant@example.com", "demo")) {
  die("Cannot login. Message: ".$session->getMessage());
}
Load affiliate data:
// loading affiliate by his ID
$affiliate = new Pap_Api_Affiliate($session);
// You can load affiliate by system user ID, referral ID or username, so one of the following commands
$affiliate->setUserid("11111111");
//$affiliate->setUsername("my@username.com");
//$affiliate->setRefid("referralID");
try {
  if(!$affiliate->load()) {
    die('Cannot load affiliate, error: '.$affiliate->getMessage());
  }
} catch (Exception $e) {
  die('Cannot load affiliate, error: '.$e->getMessage());
}
Change status of affiliate to approved and save it:
$affiliate->setStatus('A');  //A - Approved, D - Declined, P - Pending
try {
  if ($affiliate->save()) {
    echo "Affiliate saved successfully";
  } else {
    die("Cannot save affiliate: ".$affiliate->getMessage());
  }
} catch (Exception $e) {
  die("Error while communicating with PAP: ".$e->getMessage());
}
×