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
- Get emails that complained.
- Access up to 180 days of aggregated activity for a list.
- Subscribe a batch of emails.
- Unsubscribe a batch of emails.
- Retrieve the clients that the list’s subscribers have been tagged as being used.
- Access the Growth History by Month in aggregate or for a given list.
- Add a single Interest Group.
- Delete a single Interest Group.
- Change the name of an Interest Group.
- Get the list of interest groupings for a given list.
- Add a new Interest Grouping.
- Delete an existing Interest Grouping.
- Update an existing Interest Grouping.
- Retrieve all of the lists defined for your user account.
- Retrieve the locations (countries) that the list’s subscribers have been tagged to.
- Get the most recent 100 activities for particular list members.
- Get all the information for particular members of a list.
- Get all of the list members for a list.
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)
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)
Delete a single Interest Group.
MailChimp API Method:
lists/interest-group-del (string apikey, string id, string group_name, int grouping_id)
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)
Delete an existing Interest Grouping.
MailChimp API Method:
lists/interest-grouping-del (string apikey, int grouping_id)
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 Gallery Related Methods
Return a section of the image gallery.
MailChimp API Method:
gallery/list (string apikey, struct opts)
2 comments on “MailChimp PHP API Class”.
# Dec 15, 2014
Hi,thanks for the article.I wonder if you have an example for merge_vars in batchsubscibe.Thanks a lot
# Jul 31, 2014
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.
All comments posted on 'MailChimp PHP API Class' are held for moderation and only published when on topic and not rude. Get a gold star if you actually read & follow these rules.
You may write comments in Markdown. This is the best way to post any code, inline like `<div>this</div>` or multiline blocks within triple backtick fences (```) with double new lines before and after.
Want to tell me something privately, like pointing out a typo or stuff like that? Contact Me.