Send password reset email to affiliate

If you have created external login forms for your affiliates you might also need an API solution to send out a password reset email to the affiliate. Below is the code with explanations in the comments which you might use to do just that. Important parts are highlighted.


 

<?php
//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
 
//change http://demo.postaffiliatepro.com/ to the path of your Post Affiliate Pro installation
$session = new Pap_Api_Session("http://demo.postaffiliatepro.com/scripts/server.php");
   
/*
* login as merchant, replace credentials with username and password of a merchant who has access to "affiliate write" privilege,
* you can use Multiple merchants feature http://support.qualityunit.com/732104-Multiple-merchants to create a merchant with only that privilege
*/
if(!$session->login("merchant@example.com", "demo")) {
    die("Cannot login. Message: ".$session->getMessage());
}

/*
* OPTIONAL PART get the ID of an affiliate from his username which you can of course capture before,
* this part including setting of the $userid variable can be skipped if you already know the ID of the affiliate
*/
$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUsername("affiliate@example.com");
try {
  $affiliate->load();
} catch (Exception $e) {
  die("Cannot load record: ".$e->getMessage());
}
$userid= $affiliate->getUserid();

// request for the password reset email
$request = new Gpf_Rpc_Request('Pap_Merchants_User_AffiliateForm', 'sendRequestPassword', $session);
/*
* if you know the ID you can insert it directly here in place of $userid.
* you can also enter multiple IDs if you want to send such email to multiple affiliates at once,
* in such case it would be for example $request->addParam('ids', new Gpf_Rpc_Array(array('11111111','979ccb9b','761b2a5d')));
*/
$request->addParam('ids', new Gpf_Rpc_Array(array($userid))); //ID of the affiliate to whom we are sending the email

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

$response = $request->getStdResponse();

if ($response->success == 'Y') {
echo 'Success: ' . $response->infoMessage;
} else {
echo 'Unsuccess: ' . $response->errorMessage;
}
?>

In case you would want to directly set the password for the affiliate instead of sending him a password reset email you can do so by using setPassword($value) function from Pap_Api_Affiliate