Registered Users LOGIN 

MailChimp Home Learn More Pricing Resource Center Blog Free Trial

MailChimp API

Please, before you get too deep into anything, make sure that you've read our Getting Started Guide. Thanks!

Use Case Write-ups

Write-ups on some standard use cases that our customers have employed. These range from very basic to kind of complicated solutions for a variety of things:

  1. The Basic Subscribe Form

  2. Using Transactional Email Campaigns

  3. Syncing Database Changes from You to Mailchimp

  4. Syncing Database Changes from Mailchimp to You - includes parts on redirecting users to your site after Opt-in, Profile editing, etc.
  5. Reproducing our Forward-to-a-Friend Program Links

Think we missed something, or have an example you'd like us to cover? Let us know!

Sample Code

Below are some quick random examples to get you started using a number of methods. Don't forget that we also have tried to provide more specific code examples in the documentation for each function, plus there are User submitted notes that you may find useful.

Full, ready to go code examples can be found on our downloads page. Be sure to check out the READMEs!


Other snippets

  1. Using our PHP MCAPI wrapper class
  2. Using our PHP and XML-RPC
  3. Using HTTP GET/POST
  4. Merge Var Arrays via HTTP GET/POST

Example 1: Using our PHP MCAPI.class.php. (We'll go ahead and grab the credentials and list_ids since so much of the logic is handled by the class)

<?php
include('MCAPI.class.php');
$q = new MCAPI('<username>','<password>');
$lists = $q->lists();
foreach ($lists AS $list) { if ($list['name'] == 'Newsletter List') { $list_id = $list['id']; } }
$memberInfo = $q->listMemberInfo($list_id,'<email_address>');
print_r($memberInfo);
?>

Example 2: Using XML-RPC (this XML-RPC Library for PHP), but pretty much any XML-RPC Library will work with slight tweaks to syntax. Honestly, for PHP, the PEAR XML_RPC2 library is much easier to use.

<?php
include("xmlrpc.inc");
$v=new xmlrpcval(array('apikey' => new xmlrpcval('<apikey - captured from login()>'),
		               'id' =>new xmlrpcval('<list id - captured from lists()>'),
		               'email_address' => new xmlrpcval('<email_address>')),
		         'struct');
$f=new xmlrpcmsg('listMemberInfo', array($v));
$c=new xmlrpc_client("/1.1/index.phtml", "api.mailchimp.com", 80);
$r=&$c->send($f);
$response = $r->serialize();
print $response;
?>

Example 3: Using HTTP GET/POST. Here we'll just create a url that you can use in whatever method you wish to grab the data (curl, wget, raw sockets, etc).

#Return format is a php serialized array
http://api.mailchimp.com/1.1/?method=listMemberInfo
                             &apikey=<apikey - captured from login()>
                             &id=<list id - captured from lists()>
                             &email_address=<email_address>
                             &output=php

#Return format is a JSON array
http://api.mailchimp.com/1.1/?method=listMemberInfo
                             &apikey=<apikey - captured from login()>
                             &id=<list id - captured from lists()>
                             &email_address=<email_address>
                             &output=json

Example 4: Setting Merge Var arrays when using HTTP GET/POST URL strings. This is just a sample of what your URL string should look like if you wish to pass Merge Vars and/or Interest Groups into the listSubscribe() function. Other functions that accept arrays of parameters should look similar.

#Return format is a JSON array
http://api.mailchimp.com/1.1/?method=listSubscribe
                             &apikey=<apikey - captured from login()>
                             &id=<list id - captured from lists()>
                             &email_address=<email_address>
                             &merge_vars[FNAME]=Firstname
                             &merge_vars[LNAME]=Lastname
                             &merge_vars[INTERESTS]=Dogs,Cats,Shoes
                             &output=json


Was this useful? Send us your comments!



Email Marketing Resources  |   Free HTML Email Templates  |   Partners  |  Find an Expert  |   Add-ons  |   API  |   Plugins  |   Blog  |  Demos  |  Surveys  |   Webinars  |   Subscribe to our free Email Marketing Tips Newsletter

New Features:  RSS to Email  |   A/B Split Testing Emails  |   Google Analytics Integration  |   Segmentation

Truste Certified Privacy Click to verify BBB accreditation and to see a BBB report ESPC Members MAAWG Email Experience Council Members HACKER SAFE certified sites prevent over 99.9% of hacker crime.
WebAward Winner W3 Award Webby Award Nominee As featured on MSNBC's Your Business Program