Creative File Upload Script

If you are looking for a PHP example of how to upload a creative offer file, see the below code as a starting point. Simply plug in your API key and network ID, use the OfferFile::create method, and have the script point to a file in the same directory.

<?php
// Set these variables
$networkid = ""; // In your HasOffers system at Support -> API
$apikey = ""; // In your HasOffers system at Support -> API
$offerid = "0"; // Specify an offer ID to add the creative to
$creativetype = "image banner"; // Types: file, image banner, flash banner, email creative, offer thumbnail, text ad, html ad, hidden
$filename = "banner_728x90.gif"; // File name; no spaces, and file must be in same directory as this script
$display = $filename; // Or change this to the "display name" for this creative

// Don't change anything below here
$creativetype = urlencode($creativetype);
$display = urlencode($display);
$fields[$filename] = "@{$filename}";
$url = "https://{$networkid}.api.hasoffers.com/Apiv3/json?NetworkToken={$apikey}&Target=OfferFile&Method=create&data[offer_id]={$offerid}&data[type]={$creativetype}&data[display]={$display}&data[file][name]={$filename}&return_object=1";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if (phpversion() >= "5.0.0") {
    $data[$filename] = new CURLFile ($filename);
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
    $fields[$filename] = "@{$filename}";
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
}

$resp = curl_exec($ch);
curl_close($ch);
print_r(json_decode($resp, true)); // Final output; remove or change this if you want
?>
Have a Question? Please contact [email protected] for technical support.