« Back to Documentation Overview

lists – v1.1

 lists(string apikey)

Retrieve all of the lists defined for your user account

Section
List Related
Parameters
apikey a valid API Key for your user account. Get by calling Get by visiting your API dashboard
Returns
array list of your Lists and their associated information (see Returned Fields for description)
Returned Fields
stringidThe list id for this list. This will be used for all other list management functions.
stringweb_idThe list id used in our web app, allows you to create a link directly to it
stringnameThe name of the list.
datedate_createdThe date that this list was created.
integermember_countThe number of active members in the given list.

Examples (2)

download example code

[1] mcapi_lists.php

  1. <?php
  2. /**
  3. This Example shows how to pull the Members of a List using the MCAPI.php
  4. class and do some basic error checking.
  5. **/
  6. require_once 'inc/MCAPI.class.php';
  7. require_once 'inc/config.inc.php'; //contains apikey
  8.  
  9. $api = new MCAPI($apikey);
  10.  
  11. $retval = $api->lists();
  12.  
  13. if ($api->errorCode){
  14. echo "Unable to load lists()!";
  15. echo "\n\tCode=".$api->errorCode;
  16. echo "\n\tMsg=".$api->errorMessage."\n";
  17. } else {
  18. echo "Your lists:\n";
  19. foreach ($retval as $list){
  20. echo "Id = ".$list['id']." - ".$list['name']." - ".$list['web_id']."\n";
  21. echo "\tSub = ".$list['member_count']."\tUnsub=".$list['unsubscribe_count']."\tCleaned=".$list['cleaned_count']."\n";
  22. }
  23. }
  24.  

[2] xml-rpc_lists.php

  1. <?php
  2. /**
  3. This Example shows how to use XML-RPC to Retrieve all of the Lists on your
  4. account and display some info about them.
  5. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. require_once 'inc/config.inc.php';
  9. try {
  10. $client = XML_RPC2_Client::create($apiUrl);
  11.  
  12. $lists = $client->lists($apikey);
  13. echo "SUCCESS!\n";
  14. foreach ($lists as $list){
  15. echo "Id = ".$list['id']." - ".$list['name']."\n";
  16. }
  17. } catch (XML_RPC2_FaultException $e){
  18. echo "ERROR!!!!\n";
  19. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  20. }
  21. ?>
  22.