CalderaWP/laravel-mailchimp-segment

Name: laravel-mailchimp-segment

Owner: Caldera Labs

Description: Simple Laravel service for MailChimp Segments

Created: 2017-01-30 02:55:54.0

Updated: 2017-01-30 03:39:40.0

Pushed: 2017-02-19 00:13:54.0

Homepage: null

Size: 9

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

laravel-mailchimp-segment

Simple Laravel service for MailChimp Segments

Install

Usage

Primary usage is to add or remove emails from segments, but lower-level APIs are provided.

Working With Pre-Exsiting Segments

NOTE: $listId and $segmentId are assumed

Get emails from a segment
//create object for segment
$segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, ) $segmentId );

$emails = $segment->getEmails();
Add emails to a segment
//create object for segment
$segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, ) $segmentId );

//$emials will contain all emails in segment after update
//Note, addresses not in list are ignored
$emails = $segement->addEmails([
                'frodo@bagend.com',
                'bilbo@bagend.com'
            ]);
Remove emails from a segment
//create object for segment
$segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, $segmentId );

//$emials will contain all emails in segment after update
//Note, addresses not in list are ignored
$emails = $segement->removeEmails([
                'sam@bagend.com',
            ]);
Other Examples
Create segment
$segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
$listId = 'f402a6993d';
$segmentAPI->create( $listId, [
            'frodo@bagend.com',
           'bilbo@bagend.com'
        ],'Test Segment' );
Get All Segments Of A List
$segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
$listId = 'f402a6993d';
$segments = $segmentAPI->segments( $listId );
Get All Segments Of All Lists For An Account
$lists = \calderawp\mailchimp\segments\Factory::lists( config('mailchimp-segments.apiKey') );
$ids = $lists->getListIds();
$segments = [];
foreach( $ids as $listId ){
    $segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );

    $s = $segmentAPI->segments( $listId );
    $segments  = array_merge($segments, $s );
}

License, etc.

Copyrigtht 2017 CalderaWP LLC - License: GPL V2 or later


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.