PHPackages                             jhut89/mailchimp3php - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. jhut89/mailchimp3php

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jhut89/mailchimp3php
====================

A php library for version 3.0 of MailChimp's API

3.2.3(5y ago)64372.5k—1.2%25[1 issues](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/issues)[1 PRs](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/pulls)MITPHPPHP &gt;=5.5.0CI passing

Since Jan 9Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/Jhut89/Mailchimp-API-3.0-PHP)[ Packagist](https://packagist.org/packages/jhut89/mailchimp3php)[ Docs](https://github.com/Jhut89/Mailchimp-API-3.0-PHP)[ RSS](/packages/jhut89-mailchimp3php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (25)Used By (0)

Table Of Contents
=================

[](#table-of-contents)

- [MAILCHIMP API 3.0 PHP](#mailchimp-api-3.0-php)
    - [Installation](#installation)
    - [Instantiation](#instantiation)
    - [OAuth](#oauth)
    - [Constructing a Request](#constructing-a-request)
        - [GET](#get)
        - [POST](#post)
        - [PATCH &amp; PUT](#patch-put-heading)
        - [DELETE](#delete)
    - [Handling A Response](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki/Handling-A-Response)
    - [Callbacks](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki/Callbacks)
    - [Method Chart (\*excluding verbs)](#method-chart-heading)
    - [Wiki](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki) - See for more in depth documentation

MAILCHIMP API 3.0 PHP
=====================

[](#mailchimp-api-30-php)

[![GitHub license](https://camo.githubusercontent.com/1e31ae02d206f07a8afb69032850c0d499635ee60ac82d984f798f5356df7ce6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a68757438392f4d61696c6368696d702d4150492d332e302d5048502e737667)](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/3cc1bee1d44c7e5ace9e80022bad662771066c162566667c353876e529d1015f/68747470733a2f2f7472617669732d63692e636f6d2f4a68757438392f4d61696c6368696d702d4150492d332e302d5048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Jhut89/Mailchimp-API-3.0-PHP)[![Latest Stable Version](https://camo.githubusercontent.com/fea762a2a7f729722373c7c341bea2498134eec6950f7a0b4182338fc27fba3c/68747470733a2f2f706f7365722e707567782e6f72672f6a68757438392f6d61696c6368696d70337068702f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/jhut89/mailchimp3php)[![Total Downloads](https://camo.githubusercontent.com/90ae13a86b50e292752e364608b98a072de1f85b23103e4ed23a283e8dac6023/68747470733a2f2f706f7365722e707567782e6f72672f6a68757438392f6d61696c6368696d70337068702f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/jhut89/mailchimp3php)[![Slack Workspace](https://camo.githubusercontent.com/abaee8d75697342b9a7b6dd222a21dc90ff4a33e2e8ee9bed0fe2b4a30d67d52/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736c61636b253230776f726b73706163652d6a6f696e2d626c75652e7376673f7374796c653d666c6174)](https://join.slack.com/t/mailchimp-api-30-php/shared_invite/enQtMzkwNTg3Mzc5NzI5LTdhOWE2ZGE1NzJmZGRjNDg2Mzg1MDYwZmVhNGM0MGJmMDY3NGVkOWQyZTI1Zjg1YTA2YjdkMDMxNjIyZjg5MGM)[![Trello Board](https://camo.githubusercontent.com/2f5e270170b49df2c117503ec1b784dc09d8f0ef249516c677b3a95693158670/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7472656c6c6f2d76696577253230626f6172642d626c75652e7376673f7374796c653d666c6174)](https://trello.com/b/N5DRSTgL/mailchimp-api-30-sdk)

This is a PHP library for interacting with [version 3.0 of MailChimp's API](https://developer.mailchimp.com)

This library assumes a basic understanding of the MailChimp application and its associated functions.

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

[](#installation)

For Composer run:

```
composer require jhut89/mailchimp3php
```

Alternatively you may add a require line to your projects `composer.json` for the package `jhut89/mailchimp3php`.

Then run `composer update` and add the composer autoloader to your project with:

```
require "vendor/autoload.php";
```

You can then use a use statement to pull in the Mailchimp class:

```
use MailchimpAPI\Mailchimp;
```

Instantiation
-------------

[](#instantiation)

```
$mailchimp = new Mailchimp('123abc123abc123abc123abc-us0');
```

To instantiate you will need a new instance of the `Mailchimp` class with your MailChimp account's API key as its only argument.

OAuth
-----

[](#oauth)

If you are using [OAuth](http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/) to obtain an access token, this library can handle the "handshake" for you.

You must first send the user to your applications `authorize_uri`. You can get this url by calling the `Mailchimp::getAuthUrl()` statically:

```
$client_id =   '12345676543';
$redirect_url =  'https://www.some-domain.com/callback_file.php';

Mailchimp::getAuthUrl($client_id, $redirect_url);
```

Optionally, if you need to pass state information along with your request so that the callback response can be routed correctly, you can include a [state parameter](https://auth0.com/docs/protocols/state-parameters):

```
$client_id =   '12345676543';
$redirect_url =  'https://www.some-domain.com/callback_file.php';

// state information encoded into a string to be included in the URL, for example data encoded in a JWT token
$state = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

Mailchimp::getAuthUrl($client_id, $redirect_url, $state);
```

From there the user will input their username and password to approve your application and will be redirected to the `redirect_uri` you set along with a `code`.

With that `code` you can now request an access token from mailchimp. For this you will need to call the `Mailchimp::oauthExchange()` method statically like this:

```
$code = 'abc123abc123abc123abc123';
$client_id =   '12345676543';
$client_secret =  '789xyz789xyz789xyz789xyz';
$redirect_url =  'https://www.some-domain.com/callback_file.php';

Mailchimp::oauthExchange($code, $client_id, $client_secret, $redirect_url);
```

If the handshake is successful, then this method will return a string containing your API key like this: `123abc123abc123abc123abc123abc-us0`. This API key can now be used to instantiate your `Mailchimp` class as we have above.

Constructing a Request
----------------------

[](#constructing-a-request)

Once you have instantiated the `Mailchimp` class you can start constructing requests. Constructing requests is done by 'chaining' methods to the `$mailchimp` instance. In most cases this 'chain' will end with the HTTP verb for your request.

### GET

[](#get)

An Example of how to retrieve a list collection:

```
$mailchimp
    ->lists()
    ->get();
```

Retrieving an instance can be accomplished by giving a unique identifier for the instance you want as an argument to the appropriate method. For example if I wanted to retrieve a list instance from the above example I would simply pass a `list_id`, as the only argument for the `lists()` method. Like this:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->get();
```

Methods available for each position in the chain depend on what the prior method returns. For example if I wanted to retrieve subscribers from a list in my account I would:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members()
    ->get();
```

Notice that I provided a `list_id` to the `lists()` method, as there would be no way to retrieve a list of subscribers from a lists collection. The above request however will only return 10 subscriber instances from the members collection. This is because MailChimp's API uses pagination (documented [HERE](http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/#parameters)) that defaults to `count=10` and `offset=0`. This library allows you to alter query string parameters by passing them as an argument to the `GET()` method. We do this by providing an array of key-value pairs where the keys are the query parameter you wish to provide/alter and its value is the parameter's value. As an example if I wanted to retrieve the second 100 subscribers from my list I could:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members()
    ->get([
        "count" => "100",
        "offset" => "100"
    ]);
```

This would be equivalent to making a get request against:

```
Https://us0.api.mailchimp.com/3.0/lists/1a2b3c4d/members?count=100&offset=100

```

Going a little further we can retrieve a single list member by giving the `members_hash` (md5 hash of lower-case address) to the `members()` method. Like this:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members('8bdbf060209f35b52087992a3cbdf4d7')
    ->get();
```

Alternatively, in place of providing an md5 hash as the identifier to the `members()` function you can provide a contact's email address as a string and this library will do the hashing for you. Like this:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members('example@domain.com')
    ->get();
```

> You can read about `GET` requests in depth here:

### POST

[](#post)

While being able to retrieve data from your account is great we also need to be able to post new data. This can be done by calling the `POST()` method at the end of a chain. As an example subscribing an address to a list would look like this:

```
$post_params = [
    'email_address'=>'example@domain.com',
    'status'=>'subscribed'
];

$mailchimp
    ->lists('1a2b3c4d')
    ->members()
    ->post($post_params);
```

In this case I would not provide `members()` with an identifier as I want to post to its collection. Also notice that the post data is an array of key-value pairs representing what parameters I want to pass to the MailChimp API. Be sure that you provide all required fields for the endpoint you are posting to. Check [MailChimp's documentation](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members) for what parameters are required. Non-required parameters can just be added to the post data, and MailChimp will ignore any that are unusable. To illustrate here is an example of adding a subscriber to a list with some non-required parameters:

```
$merge_values = [
    "FNAME" => "John",
    "LNAME" => "Doe"
];

$post_params = [
    "email_address" => "example@domain.com",
    "status" => "subscribed",
    "email_type" => "html",
    "merge_fields" => $merge_values
]

$mailchimp
    ->lists('1a2b3c4d')
    ->members()
    ->post($post_params);
```

> You can read about `POST` requests in depth here:

###  PATCH &amp; PUT

[](#-patch--put)

This library handles PUT and PATCH request similar to that of POST requests. Meaning that `PUT()` &amp; `PATCH()` both accept an array of key-value pairs that represent the data you wish altered/provided to MailChimp. As an example if I was patching the subscriber that we subscribed above, to have a new first name, that would look like this.

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members('a1167f5be2df7113beb69c95ebcdb2fd')
    ->patch([
        "merge_fields" => ["FNAME" => "Jane"]
    ]);
```

> You can read about `PATCH` &amp; `PUT` requests in depth here: [https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki/Patch-&amp;-Put-Requests](https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki/Patch-&-Put-Requests)

### DELETE

[](#delete)

Deleting a record from MailChimp is performed with the `DELETE()` method and is constructed similar to GET requests. If I wanted to delete the above subscriber I would:

```
$mailchimp
    ->lists('1a2b3c4d')
    ->members('a1167f5be2df7113beb69c95ebcdb2fd')
    ->delete();
```

> You can read about `DELETE` requests in depth here:

Handling A Response
-------------------

[](#handling-a-response)

Methods named for http verbs such as `get()` ,`post()`, `patch()`, `put()`, or `delete()` kick off an over the wire request to MailChimp's A.P.I. Given a successful request these methods return an instance of a `MailchimpResponse`. I suggest you become familiar with this class as there are a number of modifiers and getters for different pieces of a response.

There are a number of getters we can use to interact with pieces our `MailchimpResponse` instance. Some of the more commonly used ones are:

```
$response->deserialize(); // returns a deserialized (to php object) resource returned by API
$response->getHttpCode(); // returns an integer representation of the HTTP response code
$response->getHeaders(); // returns response headers as an array of key => value pairs
$response->getBody(); // return the raw text body of the response
```

As an example, if I posses an API key but want the contact email associated with its account:

```
$mailchimp = new Mailchimp('123abc123abc123abc123abc-us0');
$account = $mailchimp
    ->account()
    ->get()

$contact_email = $account
    ->deserialize()
    ->email

print $contact_email; // outputs something like "example@domain.com"
```

> You can read about how to work with responses in depth here:

Method Chart (\*excluding verbs)
--------------------------------------------------------------------------------

[](#method-chart-excluding-verbs)

```
  mailchimp()
  |
  |----account()
  |
  |----apps()
  |
  |----automations()
  |    |
  |    |----removedSubscribers()
  |    |----emails()
  |         |
  |         |---queue()*
  |         |---pauseAll()*
  |         |---startAll()*
  |
  |----batches()
  |
  |----batchWebhooks()
  |
  |----campaignFolders()
  |
  |----campaigns()
  |    |
  |    |----cancel()*
  |    |----pause()*
  |    |----replicate()*
  |    |----resume()*
  |    |----scedule()*
  |    |----send()*
  |    |----test()*
  |    |----unschedule()*
  |    |----checklist()
  |    |----feedback()
  |    |----content()
  |
  |----connectedSites()
  |    |
  |    |----verifyScriptInstallation()*
  |
  |----conversations()
  |    |
  |    |----messages()
  |
  |----ecommStores()
  |    |
  |    |----customers()
  |    |----products()
  |    |    |
  |    |    |----variants()
  |    |    |----images()
  |    |
  |    |----promoRules()
  |    |    |
  |    |    |----promoCodes()
  |    |
  |    |----orders()
  |    |    |
  |    |    |----lines()
  |    |
  |    |----carts()
  |         |
  |         |----lines()
  |
  |----facebookAds()
  |
  |----fileManagerFiles()
  |
  |----fileManagerFolders()
  |
  |----googleAds()
  |
  |----landingPages()
  |    |
  |    |----publish()*
  |    |----unpublish()*
  |    |----content()
  |
  |----lists()
  |    |
  |    |----batchSubscribe()*
  |    |----webhooks()
  |    |----signupForms()
  |    |----mergeFields()
  |    |----growthHistory()
  |    |----clients()
  |    |----activity()
  |    |----abuseReports()
  |    |----segments()
  |    |    |
  |    |    |----batch()*
  |    |    |----members()
  |    |
  |    |----members()
  |    |    |
  |    |    |---notes()
  |    |    |---goals()
  |    |    |---activity()
  |    |    |---tags()
  |    |
  |    |----interestCategories()
  |         |
  |         |----interests()
  |
  |----ping()
  |
  |----reports()
  |    |
  |    |----unsubscribes()
  |    |----subReports()
  |    |----sentTo()
  |    |----locations()
  |    |----emailActivity()
  |    |----googleAnalytics()
  |    |----openDetails()
  |    |----eepurl()
  |    |----domainPerformance()
  |    |----advice()
  |    |----abuse()
  |    |----clickReports()
  |         |
  |         |----members()
  |
  |----searchCampaigns()
  |
  |----searchMembers()
  |
  |----templateFolders()
  |
  |----templates()
  |    |
  |    |----defaultContent()
  |
  |----verifiedDomains()
       |
       |----verify()

```

\*Please see [MailChimp's API Documentation](http://developer.mailchimp.com/documentation/mailchimp/reference/overview/) for what verbs are appropriate where.

\*\* Methods marked with a `*` make a network request

\*\*Please watch for updates, and feel free to Fork or Pull Request. Check out the Wiki for a little more info on contributing.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance53

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 83.8% 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

Every ~60 days

Recently: every ~53 days

Total

23

Last Release

2093d ago

Major Versions

1.0.2 → 2.0.012017-01-20

2.3.02 → 3.0.02018-08-26

PHP version history (3 changes)1.0.1PHP &gt;=5.3.0

2.1.03PHP &gt;=5.4.0

3.0.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/70663c991a29554fe9e2b82c681e660993dcbb2c4b8e97b49c59e436cc9aff97?d=identicon)[jhut89](/maintainers/jhut89)

---

Top Contributors

[![Jhut89](https://avatars.githubusercontent.com/u/13235920?v=4)](https://github.com/Jhut89 "Jhut89 (93 commits)")[![mmorrisson](https://avatars.githubusercontent.com/u/1872852?v=4)](https://github.com/mmorrisson "mmorrisson (7 commits)")[![andrii-pukhalevych](https://avatars.githubusercontent.com/u/3767063?v=4)](https://github.com/andrii-pukhalevych "andrii-pukhalevych (6 commits)")[![mauriciabad](https://avatars.githubusercontent.com/u/12821361?v=4)](https://github.com/mauriciabad "mauriciabad (2 commits)")[![helonaut](https://avatars.githubusercontent.com/u/1416301?v=4)](https://github.com/helonaut "helonaut (1 commits)")[![itsrexb](https://avatars.githubusercontent.com/u/3509894?v=4)](https://github.com/itsrexb "itsrexb (1 commits)")[![mgilfillan](https://avatars.githubusercontent.com/u/25685838?v=4)](https://github.com/mgilfillan "mgilfillan (1 commits)")

---

Tags

composerecommercemailchimpmailchimp-apimailchimp-api-wrappermailchimp-documentationmailchimp-phpmailchimp-sdkoauthoauth2php-librarysdksdk-phpsync

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jhut89-mailchimp3php/health.svg)

```
[![Health](https://phpackages.com/badges/jhut89-mailchimp3php/health.svg)](https://phpackages.com/packages/jhut89-mailchimp3php)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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