Follow

The example of creating the offer+logo PHP [API]

!!!Requirements: (PHP 5 >= 5.5.0, PHP 7)!!!

<?php

//Requirements: (PHP 5 >= 5.5.0, PHP 7)

$url = 'http://YOUR_API_URL/2.1/admin/offer';
$apiKey = ‘API-KEY’;
$filePath = '512x512bb.jpg';

if (version_compare(PHP_VERSION, '5.5.0') < 0) {
throw new Exception("You are using the old PHP version. Need at least 5.5.0. You version: " . PHP_VERSION);
}

if (!file_exists($filePath)) {
throw new Exception("File '{$filePath}' not exists");
};

$ch = curl_init($url);

$cfile = new CURLFile($filePath, filetype($filePath), basename($filePath));

// Assign POST data
$data = [
'logo' => $cfile,
'title' => 'CHEERZ (END April 28th) php test 2',
'advertiser' => '58fdf82f32381204778b45c4',
'url' => ‘TRACKING_URL_HERE’,
'url_preview' => ‘URL_PREVIEW_HERE’,
'description' => «DESCRIPTION»,

];
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data',
'Api-Key: ' . $apiKey
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the handle
$result = curl_exec($ch);

if ($result === false) {
throw new Exception("Curl error: " . curl_error($ch));
} else {
echo "Uploaded successfully!\n";

}

// close the session
curl_close($ch);

Was this article helpful?
1 out of 3 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.