You are here

function mailchimp_get_lists_for_email in Mailchimp 8

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_get_lists_for_email()
  2. 7.3 mailchimp.module \mailchimp_get_lists_for_email()
  3. 7.4 mailchimp.module \mailchimp_get_lists_for_email()
  4. 2.x mailchimp.module \mailchimp_get_lists_for_email()

Returns all lists a given email address is currently subscribed to.

Parameters

string $email: Email address to search.

Return value

array Campaign structs containing id, web_id, name.

File

./mailchimp.module, line 926
Mailchimp module.

Code

function mailchimp_get_lists_for_email($email) {
  try {

    /* @var \Mailchimp\MailchimpLists $mcapi */
    $mcapi = mailchimp_get_api_object('MailchimpLists');
    $lists = $mcapi
      ->getListsForEmail($email);
  } catch (\Exception $e) {
    \Drupal::logger('mailchimp')
      ->error('An error occurred retreiving lists data for {email}. "{message}"', [
      'email' => $email,
      'message' => $e
        ->getMessage(),
    ]);
    $lists = [];
  }
  return $lists;
}