Resetting Offer Application Status for Affiliates

There are a number of reasons why a network might want to have affiliates reapply to Offers. One case is when an offer has the terms and conditions updated and so they want all affiliates running the offer to reapply after agreeing to those terms. If you have experimented with the system to see if setting approved Affiliates back to unapproved status allows them to reapply you will have noticed that they are unable to do so.

Overview of Offer Approval Status

The reason for this is how the HasOffers system tracks Offer Approval status for Affiliates. An Affiliate that has never applied will appear in the unapproved box on an offer, but 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 an Affiliate'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 an affiliate that was previously set to approved is moved to the unapproved box their status will also be set to “rejected”. A rejected Affiliate is not able to reapply to an offer.

Introducing the setAffiliateApproval API Call

With this in mind, the steps to having Affiliates reapply to offers is to set their offer approval status to null. This will cause the system to treat the affiliate as if they have never applied to the offer before. To do this, we will use the API call found in this page of the API documentation: Offer::setAffiliateApproval

When filling out the fields all we need is 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

You might notice that is will only set the status of a single Affiliate on a single offer. Chances are, you want all of the affiliates running the offer to have to reapply. A PHP script is a good way to do this. This is our 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. Then run this script from a folder that also contains a file called affiliate_approval.csv. In this csv, the first column should be “id” and have the offer id(s) that you want to reset affiliate approval for. The second column should be “affiliate_id” with each id in its own row. The third column should be “status” and if you are wanting to reset the affiliate status then you should have each row in that column be null.

Have a Question? Please contact [email protected] for technical support.