« Back to Documentation Overview

apikeys – v1.1

 apikeys(string username, string password, string apikey, boolean expired)

Retrieve a list of all MailChimp API Keys for this User

Section
Security Related
Parameters
username Your MailChimp user name
password Your MailChimp password
apikey Any valid API Key
expired optional - whether or not to include expired keys, defaults to false
Returns
array an array of API keys including:
Returned Fields
stringapikeyThe api key that can be used
stringcreated_atThe date the key was created
stringexpired_atThe date the key was expired

Examples (2)

download example code

[1] xml-rpc_apikeyAdd.php

  1. <?php
  2. /**
  3. This Example shows how add an API Key to your account and then retrieve a list
  4. of all API Keys on your account using XML-RPC.
  5. Note that we are using the PEAR XML-RPC2 client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. require_once 'inc/config.inc.php';
  9.  
  10. try {
  11. $client = XML_RPC2_Client::create($apiUrl);
  12.  
  13. $result = $client->apikeyAdd($username,$password, $apikey);
  14. echo "SUCCESS! \n";
  15. echo "New API Key = ".$result."\n";
  16. echo "\n";
  17. echo "All API Keys for your account:\n";
  18. $result = $client->apikeys($username,$password, $apikey);
  19. foreach($result as $key){
  20. echo "key = ".$key['apikey']."\n";
  21. echo "\tcreated: = ".$key['created_at']."\n";
  22. echo "\texpired : = ".$key['expired_at']."\n";
  23. }
  24.  
  25. } catch (XML_RPC2_FaultException $e){
  26. echo "ERROR!!!!\n";
  27. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  28. }
  29.  

[2] mcapi_apikeyAdd.php

  1. <?php
  2. /**
  3. This Example shows how to add a new API key using the MCAPI.php class and do
  4. 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->apiKeyAdd($username, $password);
  12.  
  13. if ($api->errorCode){
  14. echo "Unable to load Add a New API Key()!";
  15. echo "\n\tCode=".$api->errorCode;
  16. echo "\n\tMsg=".$api->errorMessage."\n";
  17. } else {
  18. echo "New API Key:".$retval."\n";
  19. }
  20.