Simple Laravel service for MailChimp Segments
- composer install -- make sure to add repo as repository
- Add API key to .env file
MAILCHIMP_APIKEY='123344dfff-us10'
- Must use the single quotes!
- Add provider in config/app.php
- In package service providers add:
\calderawp\mailchimp\segments\PackageServiceProvider::class
Primary usage is to add or remove emails from segments, but lower-level APIs are provided.
NOTE: $listId
and $segmentId
are assumed
//create object for segment
$segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, ) $segmentId );
$emails = $segment->getEmails();
//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([
'[email protected]',
'[email protected]'
]);
//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([
'[email protected]',
]);
$segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
$listId = 'f402a6993d';
$segmentAPI->create( $listId, [
'[email protected]',
'[email protected]'
],'Test Segment' );
$segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
$listId = 'f402a6993d';
$segments = $segmentAPI->segments( $listId );
$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 );
}
Copyrigtht 2017 CalderaWP LLC - License: GPL V2 or later