You are here

function mailchimp_test_list_segment in Mailchimp 8

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_test_list_segment()
  2. 7.3 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_test_list_segment()
  3. 7.4 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_test_list_segment()
  4. 2.x modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_test_list_segment()

Tests a list segment, returning the number of subscribers in the segment.

Parameters

string $list_id: The list ID.

string $list_segment_id: The list segment ID.

Return value

int The number of subscribers contained in the segment.

1 call to mailchimp_test_list_segment()
mailchimp_campaign_save_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Save a campaign in Mailchimp and as a Drupal entity.

File

modules/mailchimp_campaign/mailchimp_campaign.module, line 486
Module file for mailchimp_campaign.

Code

function mailchimp_test_list_segment($list_id, $list_segment_id) {

  /* @var \Mailchimp\MailchimpLists $mc_lists */
  $mc_lists = mailchimp_get_api_object('MailchimpLists');
  try {
    $result = $mc_lists
      ->getSegmentMembers($list_id, $list_segment_id, [
      'count' => 500,
    ]);
  } catch (\Exception $e) {
    \Drupal::messenger()
      ->addError($e
      ->getMessage());
    \Drupal::logger('mailchimp_campaign')
      ->error('An error occurred testing a list segment: {message}', [
      'message' => $e
        ->getMessage(),
    ]);
    return NULL;
  }
  return $result->total_items;
}