1-866-284-2541  |  Registered Users LOGIN 

MailChimp Home Learn More Pricing Resource Center Free Trial

MailChimp API
Back to Documentation Overview

Super Duper Quick API Example 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.

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('uid' => new xmlrpcval('<uid - 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.0/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.0/?method=listMemberInfo
                             &uid=<uid - 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.0/?method=listMemberInfo
                             &uid=<uid - captured from login()>
                             &id=<list id - captured from lists()>
                             &email_address=<email_address>
                             &output=json


Sample PHP Code

Our own Aarron Walter has provided a couple of quick, AJAX + PHP examples that he discusses in his Building Findable Websites book, and on SitePoint.

download PHP ClassSimple example with only an email signup box

download PHP ClassExample with email and mailing address fields


Was this useful? Send us your comments!



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

Truste Certified Privacy BBB Members ESPC Members 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 Made on a Mac