| Home | Learn More | Pricing | Resource Center |
![]() |
Back to Documentation Overview
Super Duper Quick API Example codeBelow 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 CodeOur own Aarron Walter has provided a couple of quick, AJAX + PHP examples that he discusses in his Building Findable Websites book, and on SitePoint. 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 © 2001-2007 MailChimp. All Rights Reserved.  | Toll-Free: 1-866-284-2541 |
|