PHPackages                             chimpmatic/mailchimp-api-key-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. chimpmatic/mailchimp-api-key-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

chimpmatic/mailchimp-api-key-validator
======================================

Validate Mailchimp API key format, detect common errors (whitespace, missing datacenter suffix), and verify connectivity.

v1.0.0(6d ago)02↓100%MITPHPPHP &gt;=7.4

Since Mar 17Pushed 6d agoCompare

[ Source](https://github.com/chimpmatic/mailchimp-api-key-validator)[ Packagist](https://packagist.org/packages/chimpmatic/mailchimp-api-key-validator)[ Docs](https://chimpmatic.com)[ RSS](/packages/chimpmatic-mailchimp-api-key-validator/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

Mailchimp API Key Validator
===========================

[](#mailchimp-api-key-validator)

[![Latest Version](https://camo.githubusercontent.com/20bbfa27dbf054c4bba69165c31955d09c566c3e1a5553effdc2335d25ca67d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696d706d617469632f6d61696c6368696d702d6170692d6b65792d76616c696461746f722e737667)](https://packagist.org/packages/chimpmatic/mailchimp-api-key-validator)[![PHP Version](https://camo.githubusercontent.com/03e1353078463cecd40a952d57e85a2ee8a3ad3e2fb1af5f15fdadda64739a12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6368696d706d617469632f6d61696c6368696d702d6170692d6b65792d76616c696461746f722e737667)](https://packagist.org/packages/chimpmatic/mailchimp-api-key-validator)[![License](https://camo.githubusercontent.com/bb505d32a6411d56f4e94d782f926ab635a1a5f84152d2441cf30e43f251ac11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6368696d706d617469632f6d61696c6368696d702d6170692d6b65792d76616c696461746f722e737667)](https://github.com/chimpmatic/mailchimp-api-key-validator/blob/main/LICENSE)

Validate Mailchimp API key format, detect common errors, and optionally verify connectivity — all without hitting the Mailchimp API until you're ready.

**Author:** [Chimpmatic](https://chimpmatic.com)

Why This Exists
---------------

[](#why-this-exists)

The most common support request for any Mailchimp integration is **"Invalid API Key."** The causes are always the same:

- Extra whitespace when pasting
- Missing datacenter suffix (`-us4`)
- Truncated key (copied only part of it)
- Revoked or disabled key

This library catches all of these **before** making an API call, giving your users clear error messages instead of a generic failure.

Need to get your Mailchimp API key first? See [How to Get Your Mailchimp API Key](https://chimpmatic.com/how-to-get-your-mailchimp-api-key) for a one-click shortcut.

Installation
------------

[](#installation)

```
composer require chimpmatic/mailchimp-api-key-validator
```

Quick Start
-----------

[](#quick-start)

```
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;
    }
}
```

Connectivity Verification
-------------------------

[](#connectivity-verification)

Optionally verify the key works against the Mailchimp API (requires `curl`):

```
$result = $validator->verifyConnectivity('aaaaaaaaaabbbbbbbbbbccccccccccdd-us4');

if ($result->isValid()) {
    echo 'Connected to Mailchimp!';
    echo $result->getHttpStatus(); // 200
}
```

What It Catches
---------------

[](#what-it-catches)

IssueDetectionMessageEmpty keyFormat check`API key is empty.`Leading/trailing whitespaceFormat checkWarning + auto-trimInternal whitespaceFormat check`Key contains whitespace characters.`Missing `-us4` suffixFormat check`Missing datacenter suffix.`Wrong hash lengthFormat check`Key hash is N characters, expected 32.`Non-hex charactersFormat check`Key hash contains non-hexadecimal characters.`Invalid datacenter formatFormat check`Datacenter "X" does not match expected format.`Unknown datacenterFormat checkWarning (may be newer DC)Revoked/disabled keyConnectivity check`API key is rejected by Mailchimp.`Insufficient permissionsConnectivity check`API key lacks sufficient permissions.`ValidationResult API
--------------------

[](#validationresult-api)

```
$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
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- `curl` extension (only for `verifyConnectivity()`)

Testing
-------

[](#testing)

```
composer test
```

Or run PHPUnit directly:

```
vendor/bin/phpunit
```

Links
-----

[](#links)

- [Packagist](https://packagist.org/packages/chimpmatic/mailchimp-api-key-validator)
- [GitHub](https://github.com/chimpmatic/mailchimp-api-key-validator)
- [Issues](https://github.com/chimpmatic/mailchimp-api-key-validator/issues)
- [How to Get Your Mailchimp API Key](https://chimpmatic.com/how-to-get-your-mailchimp-api-key)
- [Chimpmatic — Contact Form 7 to Mailchimp](https://chimpmatic.com)

License
-------

[](#license)

MIT License. Copyright (c) 2026 [Chimpmatic](https://chimpmatic.com).

###  Health Score

36

—

LowBetter than 83% of packages

Maintenance98

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

6d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0fe8014730461a907cfbc1b54ca0783ef523afa729ea89739cf96feaa78880e?d=identicon)[chimpmatic](/maintainers/chimpmatic)

---

Top Contributors

[![chimpmatic](https://avatars.githubusercontent.com/u/73747745?v=4)](https://github.com/chimpmatic "chimpmatic (1 commits)")

---

Tags

validatorwordpressmailchimpapi-keycontact-form-7mailchimp-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chimpmatic-mailchimp-api-key-validator/health.svg)

```
[![Health](https://phpackages.com/badges/chimpmatic-mailchimp-api-key-validator/health.svg)](https://phpackages.com/packages/chimpmatic-mailchimp-api-key-validator)
```

###  Alternatives

[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M28](/packages/wixel-gump)[johnstevenson/json-works

Create, edit, query and validate json

272.5M4](/packages/johnstevenson-json-works)[phpexperts/datatype-validator

An easy to use data type validator (both strict and fuzzy).

141.1M2](/packages/phpexperts-datatype-validator)[kiczort/polish-validator

Validators for Polish identification numbers: PESEL, NIP, REGON.

11120.0k5](/packages/kiczort-polish-validator)[articus/data-transfer

Library for merging source data to destination data only if destination data remains valid after that

1029.5k4](/packages/articus-data-transfer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
