Add DirectLink URL via API

Here is an example of how to add a DirectLink URL via API using merchant login credentials.
 
NOTE: You will need to know the exact userid of the affiliate to whom the DirectLink URL should be assigned.
You can get the userid of an affiliate via the following API:
https://support.qualityunit.com/608550-Pap_Api_AffiliatesGrid

while you can filter the affiliate via his/her username (e-mail address).
 
<?php
// the PapApi.class.php file can be downloaded from the merchant panel at:
// Tools > Integration > API Integration > Download PAP API
// This include assumes the PapApi.class.php file is in the same directory as this particular script. 
include 'PapApi.class.php';

$session = new Pap_Api_Session("https://URL_TO_PAP/scripts/server.php"); 
if(!$session->login("merchant@username.com", "password")) {
  die("Cannot login. Message: ".$session->getMessage());
}

$request = new Gpf_Rpc_FormRequest("Pap_Merchants_User_DirectLinksForm", "add", $session);
//Leave it blank, it is populated automatically
$request->setField('Id','');

//MANDATORY - userid of affiliate to whom the DirectLink URL will be assigned
$request->setField('userid','11111111'); 

//MANDATORY - DirectLink URL pattern
$request->setField('url','*DirectLink_URL/via/api*'); 

//MANDATORY - possible values: A,P,D
$request->setField('rstatus','A');

//OPTIONAL
//Leave it blank = All campaigns
//alternatively define a particular Campaign ID
$request->setField('campaignid',''); 

//OPTIONAL
$request->setField('channelid',''); 

//OPTIONAL
$request->setField('bannerid',''); 

//OPTIONAL - note for the merchant
$request->setField('note',''); 

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

// Get the response
$response = $request->getStdResponse();
if ($response->success == 'Y') { 
echo 'Success: ' . $response->message; 
} else { 
echo 'Unsuccess: ' . $response->message; 
}
?>
NOTE: In the above-mentioned example you must replace URL_TO_PAP  with the real URL leading to your installation of Post Affiliate Pro (or Network).
Also, you will have to replace merchant@username.compassword with your merchant panel login credentials.
×