There are a number of reasons why a network might want to have partners reapply to Offers. One case is when an offer has the terms and conditions updated and so they want all partners running the offer to reapply after agreeing to those terms.
Overview of Offer Approval Status
The TUNE system tracks the Offer Approval status for all partners. A partner that has never applied will appear in the unapproved box on an offer and their status is set to null. When they apply to the offer they will still appear in the unapproved box and their status will be set to “Pending”. If approved, they are set to “Approved”.
Here is where it gets a little tricky: if a partner's application is rejected their status will be set as “Rejected” and their name will still appear in the unapproved box. This is different from the “Blocked” status as they are still able to see the offer, but they cannot run it. If a partner that was previously set to "Approved" is moved to the unapproved box their status will also be set to “Rejected”. A rejected partner is not able to reapply for an offer.
Introducing the setAffiliateApproval API Call
With this in mind, the method for having partners reapply to offers is to set their offer approval status to null. This will cause the system to treat the partners as if they have never applied to the offer before. To do this, use the API call found on this page of the API documentation: Offer::setAffiliateApproval
You will need the id, (which is the offer id), affiliate_id, and status, (which should be set to null). The API call should end up looking something like this:
https://NETWORKID.api.hasoffers.com/Apiv3/json?NetworkToken=TOKEN&Target=Offer&Method=setAffiliateApproval&status=
Automating this process with a PHP Script
This call will only set the status of a single partner on a single offer. If multiple partners need applications reset, a PHP script is an excellent way to do this. Here is an example of a script that can do this task:
<?php
$NetworkID = "NETWORKID"; //CHANGE THIS TO YOUR NETWORK ID
$NetworkToken = "NETWORKTOKEN"; //CHANGE THIS TO YOUR API KEY
$ApiDomain = "APIDOMAIN"; //CHANGE THIS TO YOUR NETWORK ID.api.hasoffers.com
$file = @fopen("affiliate_approval.csv", "r");
if ($file) {
echo("Reading in File...n");
$rownum = 1;
while (($data = fgetcsv($file,100000,",")) !== false) {
$colnum = count($data);
//Check if it is the first row. If it is, grab headers.
if($rownum == 1){
for($i = 0; $i < $colnum; $i++){
$headers[$i] = $data[$i];
}
} else {
//parse the file
for($i = 0; $i < $colnum; $i++){
$offer[$headers[$i]] = $data[$i];
}
$response = importOffer($NetworkID, $NetworkToken, $ApiDomain, $offer);
if($response["response"]["status"] != 1){
echo("Error with offer ID: {$offer["id"]}. Check error log.n");
file_put_contents("errorLog.txt", print_r($response, true), FILE_APPEND);
} else {
file_put_contents("successLog.txt", print_r($response, true), FILE_APPEND);
echo("Updated offer ID: {$offer["id"]}n");
}
}
$rownum++;
}
}
function importOffer($NetworkID, $NetworkToken, $ApiDomain, $offerData){
$base = $ApiDomain."/Api?";
$params = array(
"Format" => "json",
"Target" => "Offer",
"Method" => "setAffiliateApproval",
"Service" => "HasOffers",
"Version" => 3,
"NetworkId" => $NetworkID,
"NetworkToken" => $NetworkToken,
"id" => $offerData["id"],
"data" => $offerData
);
$url = $base . http_build_query( $params );
$result = file_get_contents( $url );
$array = json_decode($result, true);
return $array;
}
?>
After downloading the script, open it up to insert your network id, API key, and API domain. Run this script from a folder that also contains a file called affiliate_approval.csv. In the CSV, the first column should be “id” and have the offer id(s) that you want to reset partner approval for. The second column should be “affiliate_id” with each id in its own row. The third column should be “status”. To reset the partner status then you should have each row in that column be null.