MailChimp PHP API Class: Simple Library for MailChimp API V2

The past couple of months I’ve been working to move a little over 260,000 subscribers from Eloqua to MailChimp. The company that owns the site does heavy email marketing that differs from the typical MailChimp user. This requires some advanced functionality that MailChimp’s interface does not provide. The solution, MailChimp API which allows us to build out our own custom functionality where MailChimp falls short.

The past couple of months I’ve been working to move a little over 260,000 subscribers from Eloqua to MailChimp. The company that owns the site does heavy email marketing that differs from the typical MailChimp user. This requires some advanced functionality that MailChimp’s interface does not provide. The solution, MailChimp API which allows us to build out our own custom functionality where MailChimp falls short.

I was going to build out my own MailChimp PHP API class, but luckily after a little digging, found Drew McLellan‘s MailChimp v2 wrapper. Unlike a lot of the PHP libraries out that are complex, confusing wrappers, this one is super-simple and light-weight. It allows you to quickly access the MailChimp API and start coding your own applications.

Download the MailChimp PHP API Class

MailChimp PHP API Class

Using this MailChimp PHP API Class is as simple as the class is itself. You can either download it by clicking the button above or install the mailchimp-api using Composer. In order to install it with Composer, see the docs for more details.

Once you’ve got it installed, you’ll be ready to build out your application. Just grab your MailChimp API key and initialize the class.

Once initialized, you can begin calling out to the MailChimp API and request the data or functionality you need for your app.

MailChimp PHP API Class Examples

I’m a visual learner, so put together some examples for the MailChimp PHP API Class. I’m also interested in how others use APIs to build out applications. Be sure to comment below and let me know how you’ve integrated this API for your projects.

List Related Methods

List Related Methods

These are just a few examples using the MailChimp API. Check out their docs for a full list and details of all the methods they provide.


MailChimp List Related Methods

Get emails that complained.

MailChimp API Method:
lists/abuse-reports (string apikey, string id, int start, int limit, string since)

Access up to 180 days of aggregated activity for a list (does not include AutoResponder activity).

MailChimp API Method:
lists/activity (string apikey, string id)

Subscribe a batch of emails.

MailChimp API Method:
lists/batch-subscribe (string apikey, string id, array batch, boolean double_optin, boolean update_existing, boolean replace_interests)

Maximum batch sizes vary based on the amount of data in each record, though you should cap them at 5k – 10k records, depending on your experience. These calls are also long, so be sure you increase your timeout values.

Unsubscribe a batch of emails.

MailChimp API Method:
lists/batch-unsubscribe (string apikey, string id, array batch, boolean delete_member, boolean send_goodbye, boolean send_notify)

Retrieve the clients that the list’s subscribers have been tagged as being used.

MailChimp API Method:
lists/clients (string apikey, string id)

Access the Growth History by Month in aggregate or for a given list.

MailChimp API Method:
lists/growth-history (string apikey, string id)

Add a single Interest Group.

MailChimp API Method:
lists/interest-group-add (string apikey, string id, string group_name, int grouping_id)

If interest groups for the List are not yet enabled, adding the first group will automatically turn them on.

Delete a single Interest Group.

MailChimp API Method:
lists/interest-group-del (string apikey, string id, string group_name, int grouping_id)

If the last group for a list is deleted, this will also turn groups for the list off.

Change the name of an Interest Group.

MailChimp API Method:
lists/interest-group-del (string apikey, string id, string old_name, string new_name, int grouping_id)

Get the list of interest groupings for a given list.

MailChimp API Method:
lists/interest-groupings (string apikey, string id, bool counts)

Add a new Interest Grouping.

MailChimp API Method:
lists/interest-grouping-add (string apikey, string id, string name, string type, array groups)

If interest groups for the List are not yet enabled, adding the first grouping will automatically turn them on.

Delete an existing Interest Grouping.

MailChimp API Method:
lists/interest-grouping-del (string apikey, int grouping_id)

This will permanently delete all contained interest groups and will remove those selections from all list members.

Update an existing Interest Grouping.

MailChimp API Method:
lists/interest-grouping-update (string apikey, int grouping_id, string name, string value)

Retrieve all of the lists defined for your user account.

MailChimp API Method:
lists/list (string apikey, struct filters, int start, int limit, string sort_field, string sort_dir)

Retrieve the locations (countries) that the list’s subscribers have been tagged to.

MailChimp API Method:
lists/locations (string apikey, string id)

Get the most recent 100 activities for particular list members.

MailChimp API Method:
lists/member-activity (string apikey, string id, array emails)

Get all the information for particular members of a list.

MailChimp API Method:
lists/member-info (string apikey, string id, array emails)

Get all of the list members for a list.

MailChimp API Method:
lists/members (string apikey, string id, string status, struct opts)

MailChimp API Method:
gallery/list (string apikey, struct opts)

Author: Ben Marshall

Red Bull Addict, Self-Proclaimed Grill Master, Entrepreneur, Workaholic, Front End Engineer, SEO/SM Strategist, Web Developer, Blogger

2 thoughts on “MailChimp PHP API Class: Simple Library for MailChimp API V2”

  1. Hi thanks for the article. It really helped. I want to send campaign to the list of subscribers with Mail chimp Api v2.0. What would be the steps for this.

Leave a Reply

Your email address will not be published. Required fields are marked *