PHP code example of chimpmatic / mailchimp-api-key-validator
1. Go to this page and download the library: Download chimpmatic/mailchimp-api-key-validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chimpmatic / mailchimp-api-key-validator example snippets
use Chimpmatic\MailchimpKeyValidator\ApiKeyValidator;
$validator = new ApiKeyValidator();
// Format validation (no network call)
$result = $validator->validate('aaaaaaaaaabbbbbbbbbbccccccccccdd-us4');
if ($result->isValid()) {
echo $result->getDatacenter(); // "us4"
echo $result->getHash(); // "aaaaaaaaaabbbbbbbbbbccccccccccdd"
} else {
foreach ($result->getErrors() as $error) {
echo $error;
}
}
$result = $validator->verifyConnectivity('aaaaaaaaaabbbbbbbbbbccccccccccdd-us4');
if ($result->isValid()) {
echo 'Connected to Mailchimp!';
echo $result->getHttpStatus(); // 200
}
$result->isValid(); // bool — true if no errors
$result->getErrors(); // string[] — list of error messages
$result->getWarnings(); // string[] — list of warning messages
$result->hasWarnings(); // bool — true if warnings exist
$result->getSanitizedKey(); // string — trimmed key
$result->getHash(); // ?string — 32-char hex hash or null
$result->getDatacenter(); // ?string — datacenter ID or null
$result->getHttpStatus(); // ?int — HTTP status from connectivity check
$result->getSummary(); // string — human-readable summary