Created
November 28, 2021 07:25
-
-
Save tiborepcek/cee530a1f2969196eba292ddb9e724ea to your computer and use it in GitHub Desktop.
This PHP script gets number of contats in a list of SmartEmailing.cz using their API.
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="Cache-Control" content="no-store" /> | |
<meta http-equiv="Cache-Control" content="no-cache" /> | |
<meta http-equiv="Pragma" content="no-cache" /> | |
<meta http-equiv="expires" content="mon, 27 sep 2010 14:30:00 GMT" /> | |
<title>SmartEmailing.cz - get number of contacts in a list</title> | |
</head> | |
<body> | |
<h1>SmartEmailing.cz - get number of contacts in a list</h1> | |
<p>Data updated at <b><?php echo date("d. m. Y, H:i:s");?></b></p> | |
<?php | |
$list_2088 = se_api("https://app.smartemailing.cz/api/v3/contactlists/2088/distribution"); | |
$list_2089 = se_api("https://app.smartemailing.cz/api/v3/contactlists/2089/distribution"); | |
$list_2090 = se_api("https://app.smartemailing.cz/api/v3/contactlists/2090/distribution"); | |
$total = $list_2088 + $list_2089 + $list_2090; | |
?> | |
<p>Number of contacts in list ID 2088: <b><?php echo $list_2088;?></b></p> | |
<p>Number of contacts in list ID 2089: <b><?php echo $list_2089;?></b></p> | |
<p>Number of contacts in list ID 2090: <b><?php echo $list_2090;?></b></p> | |
<p>Total: <b><?php echo $total;?></b></p> | |
</body> | |
</html> | |
<?php | |
function se_api($url) { // docs: https://app.smartemailing.cz/docs/api/v3/index.html | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | |
curl_setopt($curl, CURLOPT_USERPWD, 'username:api_key'); // get username (e-mail address) and API key at https://app.smartemailing.cz/userinfo/api-keys/ | |
$output = curl_exec($curl); | |
curl_close($curl); | |
$json = json_decode($output, true); | |
return $json["data"]["total"]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment