Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakitadog/5c94a844428b40d47793a02fec34d702 to your computer and use it in GitHub Desktop.
Save nakitadog/5c94a844428b40d47793a02fec34d702 to your computer and use it in GitHub Desktop.
<?php
$response = get_total_active_subscribers_for_tag();
if ($response <> null and $response <> -1) {
echo "\n\nTotal Subscribers for tag = " . $response;
} else {
//There were errors from the server
}
function get_total_active_subscribers_for_tag(){
$url = "https://youraccountname.api-us1.com";
$api_key = "123456789012345678901234567890123456789012345678901234567890123456789012";
$filters = http_build_query([
'tagid' => '187',
'status' => '1',
'limit' => '1',
'orders[email]'=> 'ASC' //'DESC'
]);
$final_url = $url."/api/3/contacts/?".$filters;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$final_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Api-Token: ".$api_key));
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output, true);
//echo $result["meta"]["total"];
if (ctype_digit($result["meta"]["total"])) {
return $result["meta"]["total"];
} else {
echo "There were errors from the server<br><br>\n\n";
echo 'The entire <b>$output</b> printed out:<br />';
echo '<pre>';
print_r($output);
echo '</pre>';
echo 'Raw <b>$result</b> printed out:<br />';
echo '<pre>';
print_r($result);
echo '</pre>';
echo '<br /><br />';
echo 'The entire <b>$ch</b> printed out:<br />';
echo '<pre>';
print_r($ch);
echo '</pre>';
return -1;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment