Created
March 18, 2022 14:28
-
-
Save nakitadog/5c94a844428b40d47793a02fec34d702 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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