I am trying to add a user that is in the list to a segment using drewm's Mailchimp php API wrapper
Creating the segment if it doesn't exist works fine, and it displays in the MailChimp environment. If I then try to add a subscriber using POST /lists/{list_id}/segments/{segment_id}
, the API responds like it should, stating that the subscriber has been added to the segment, or telling me the subscriber hasn't been added if the subscriber is already in the segment. But in the MailChimp admin, the segment still displays as empty. Here is my code, I have no idea where I'm going wrong:
// Segmentation
// Check if event has segment linked, if not, create segment and add to post meta
$event_segment = get_post_meta($event->post_id, 'byron_mailchimp_segment', true);
if (empty($event_segment)) {
// Create new segment,
$create_segment_response = $MailChimp->post('/lists/' . $event_list . '/segments/', [
'name' => 'Aangemeld',
'static_segment' => [],
]);
$event_segment = $create_segment_response['id'];
// Save segment ID to post meta
add_post_meta($event->post_id, 'byron_mailchimp_segment', $event_segment);
}
$add_to_segment_response = $MailChimp->post('/lists/' . $event_list . '/segments/' . $event_segment, [
'members_to_add' => [$member['user_email']],
]);
echo "<pre>";
var_dump($add_to_segment_response);
echo "</pre>";
I've already checked if the $event_segment contains the right ID, and it does.