You are here

function mailchimp_get_members in Mailchimp 8

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

Retrieve all members of a given list with a given status.

Note that this function can cause locking an is somewhat slow. It is not recommended unless you know what you are doing! See the MCAPI documentation.

1 call to mailchimp_get_members()
mailchimp_lists_get_subscribers in modules/mailchimp_lists/mailchimp_lists.module
Batch processor for pulling in subscriber information for a list/audience.

File

./mailchimp.module, line 740
Mailchimp module.

Code

function mailchimp_get_members($list_id, $status = 'subscribed', $options = []) {
  $results = FALSE;
  $lock = \Drupal::lock();
  if ($lock
    ->acquire('mailchimp_get_members', 60)) {
    try {

      /* @var \Mailchimp\MailchimpLists $mcapi */
      $mcapi = mailchimp_get_api_object('MailchimpLists');
      $options['status'] = $status;
      $options['count'] = 500;
      $results = $mcapi
        ->getMembers($list_id, $options);
    } catch (\Exception $e) {
      \Drupal::logger('mailchimp')
        ->error('An error occurred pulling member info for a list. "{message}"', [
        'message' => $e
          ->getMessage(),
      ]);
    }
    $lock
      ->release('mailchimp_get_members');
  }
  return $results;
}