Skip to content

Instantly share code, notes, and snippets.

@rutger1140
Created June 4, 2014 10:00
Show Gist options
  • Save rutger1140/7622faa59baaed05f093 to your computer and use it in GitHub Desktop.
Save rutger1140/7622faa59baaed05f093 to your computer and use it in GitHub Desktop.
Campaign Monitor - get campaign recipient totals
<!doctype html>
<html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Campaign Monitor - get campaign recipient totals</title>
<meta name="viewport" content="width=device-width">
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-header">Results</h1>
<?php
$client_id = "";
$token = "";
$curl = curl_init('https://api.createsend.com/api/v3.1/clients/'.$client_id.'/campaigns.json');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, $token.':x');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Check campaigns sent');
$responseJson = curl_exec($curl);
$resultStatus = curl_getinfo($curl);
$TotalOverall = 0;
if($resultStatus['http_code'] == 200) :
$response = json_decode($responseJson); ?>
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Campaign subject</th>
<th>Recipients</th>
</tr>
</thead>
<tbody>
<?php foreach ($response as $campaign) :
$TotalOverall += $campaign->TotalRecipients; ?>
<tr>
<td><?php echo $campaign->SentDate; ?></td>
<td><?php echo $campaign->Subject; ?> (<a href="<?php echo $campaign->WebVersionURL; ?>">Link</a>)</td>
<td><?php echo $campaign->TotalRecipients; ?></td>
</tr>
<?php endforeach ?>
<tr class="info">
<td colspan="2"></td>
<td >
<?php echo $TotalOverall; ?>
</td>
</tr>
</tbody>
</table>
<h2>Debug</h2>
<pre>
<?php
print_r($response); ?>
</pre>
<?php else : ?>
<h2>Debug</h2>
<p>
Error fetching!
</p>
<?php endif; ?>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment