1-866-284-2541  |  Registered Users LOGIN 

MailChimp Home Learn More Pricing Resource Center Blog Free Trial

MailChimp API
Back to Documentation Overview

listBatchSubscribe

public static listBatchSubscribe(string uid, string id, array batch, boolean double_optin, boolean update_existing, boolean replace_interests)

Subscribe a batch of email addresses to a list at once


Section:
List Related

Parameters:
uid the id for your user account. Get by calling login($user, $pass)
id the list id to connect to
batch an array of structs for each address to import with two special keys: "EMAIL" for the email address, and "EMAIL_TYPE" for the email type option (html or text)
double_optin flag to control whether to send an opt-in confirmation email - defaults to true
update_existing flag to control whether to update members that are already subscribed to the list or to return an error, defaults to false (return error)
replace_interests flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)

Returns:
struct   -  Array of result counts and any errors that occurred

Returned Fields:
integer success_count Number of email addresses that were succesfully added/updated
integer error_count Number of email addresses that failed during addition/updating
array errors Array of error structs. Each error struct will contain "code", "message", and the full struct that failed

Examples (1)

[1] xml-rpc_listBatchSubscribe.php

  1. <?php
  2. /**
  3. This Example shows how to use the XML-RPC service to Batch Subscribe many emails
  4. to each of your Lists and do some basic error checking.
  5. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  6.  
  7. Realize that these emails are bogus and being generated - you should not do that.
  8. **/
  9. require_once 'XML/RPC2/Client.php';
  10. include('inc/config.inc.php'); //contains username & password
  11.  
  12. $client = XML_RPC2_Client::create($apiUrl);
  13. $uuid = $client->login($username,$password);
  14.  
  15. $lists = $client->lists($uuid);
  16.  
  17. foreach ($lists as $list){
  18. echo "\n----------------[".$list['id']."]------------\n";
  19. $batch = array();
  20. for($i = 0; $i < 2000; $i++){
  21. $batch[] = array("EMAIL"=>$list['id'].'_'.$i.'@nodelivery.com');
  22. }
  23. try {
  24. /**
  25. Note that there is a limit to the number of addresses that can be batch subscribed.
  26. Here we are using 2000, which should be fine. We recommend you not attempt to add
  27. more than 5000-10,000 addresses per call to listBatchSubscribe()
  28. */
  29. $result = $client->listBatchSubscribe($uuid, $list['id'], $batch, false, false, false);
  30. echo "SUCCESS! \n";
  31. var_dump($result);
  32. } catch (XML_RPC2_FaultException $e){
  33. echo "ERROR!!!!\n";
  34. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  35. }
  36. echo "\n";
  37. }
  38. ?>
  39.  
Add New Note User Contributed Notes
listBatchSubscribe
Anders Heie : http://www.kadonk.com : listpope -at- cox -dot- net
2008-06-18 06:27:23
Example Language: csharp
 The documentation confused me a little at first, so here is what I realized:

replace_interests = true: ALL interests provided in call replace all existing interests.
replace_interests = false: Interests provided in call are ADDED to existing interests.

Also note, that the merges[i].name should be set to the .tag. while the LAST merge is used for interests, and so merges[last].name = .name.

Hopefully that will help others.

Torsten Muller : http://midwestweekends.com : diwadidu -at- yahoo -dot- com
2008-06-15 07:47:42
Example Language: php
 
The name of the array element that holds the returned data that could not be processed is "row", like this:

  1. [0] => Array
  2. (
  3. [code] => INVALID_EMAIL
  4. [message] => Invalid Email Address: tm@dfkjg@.com
  5. [row] => Array
  6. (
  7. [EMAIL] => tm@dfkjg@.com
  8. [EMAIL_TYPE] => html
  9. [FNAME] => Torsten
  10. [LNAME] => Muller
  11. )
  12.  
  13. )

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