-3

Working with MailChimp API 3. I'm trying to create a query to get the amount of emails sent in the month. Does anyone know it that is a possible request to make?

If so does anyone know the correct query to make?

1 Answers1

0

I've solved my issue. What I did to achieve the required result is below if it helps anyone else.

$firstofmonth = date("Y-m-01"); // Date from when you want the count to begin
$arr = array(); 
$ch = curl_init();
$url =  "https://" . $server . "api.mailchimp.com/3.0/reports?since_send_time=" . $firstofmonth;

curl_setopt($ch, CURLOPT_USERPWD, 'apikey:' . $api_key);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic ' . $auth
));

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);

$result=curl_exec($ch);
curl_close($ch);

$results = json_decode($result, true);

$reports = $results['reports'];

$emails_sent = 0;

foreach ($reports as $row){

$emails_sent += $row['emails_sent'];
}

$arr[]  = array
(
 "emailssent" => $emails_sent
);

 echo json_encode($arr);