| Home | Learn More | Pricing | Resource Center | Blog |
|
|
|
Please, before you get too deep into anything, make sure that you've read our Getting Started Guide. Thanks! Use Case Write-upsWrite-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:
Sample 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.
Other snippets
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 © 2001-2009 MailChimp. All Rights Reserved. |
|