### Install laravel-mailchimp via Composer Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-mailchimp ``` -------------------------------- ### Campaigns resource usage Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Campaigns resource usage: list, get, create, and send. ```php $campaigns = Mailchimp::campaigns()->list(count: 10, offset: 0, status: 'sent', type: 'regular'); $campaign = Mailchimp::campaigns()->get('c1'); Mailchimp::campaigns()->create( listId: 'abc123', type: 'regular', subject: 'Hello!', fromName: 'Jane', replyTo: 'jane@example.com', title: 'Welcome campaign', ); Mailchimp::campaigns()->send('c1'); ``` -------------------------------- ### Lists resource usage Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Lists resource usage: list with pagination and get by ID. ```php use JeffersonGoncalves\Mailchimp\Facades\Mailchimp; $lists = Mailchimp::lists()->list(count: 10, offset: 0); $list = Mailchimp::lists()->get('abc123'); ``` -------------------------------- ### Reports resource usage Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Reports resource usage: get a report by campaign ID. ```php $report = Mailchimp::reports()->get('c1'); ``` -------------------------------- ### Run tests Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Run the test suite. ```bash composer test ``` -------------------------------- ### Mailchimp configuration file Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Configuration file for the package. The api_key is read from the MAILCHIMP_API_KEY environment variable. ```php // config/mailchimp.php return [ 'api_key' => env('MAILCHIMP_API_KEY', ''), ]; ``` -------------------------------- ### Publish mailchimp-config Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Publish the package configuration file. ```bash php artisan vendor:publish --tag=mailchimp-config ``` -------------------------------- ### Automations resource usage Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Automations resource usage: list automations with pagination. ```php $automations = Mailchimp::automations()->list(count: 10, offset: 0); ``` -------------------------------- ### Members resource usage Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Members resource usage: list, add, and update. The update method requires the subscriber hash (MD5 of lowercase email). ```php $members = Mailchimp::members()->list('abc123', count: 10, offset: 0, status: 'subscribed'); Mailchimp::members()->add( listId: 'abc123', email: 'jane@example.com', status: 'subscribed', firstName: 'Jane', lastName: 'Doe', tags: ['vip'], ); Mailchimp::members()->update( listId: 'abc123', subscriberHash: md5(strtolower('jane@example.com')), status: 'unsubscribed', ); ``` -------------------------------- ### Set MAILCHIMP_API_KEY in .env Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Set the Mailchimp API key in the .env file. The datacenter suffix (e.g., us21) is used to derive the API endpoint automatically. ```env MAILCHIMP_API_KEY=your-api-key-us21 ``` -------------------------------- ### Error handling with MailchimpException Source: https://github.com/jeffersongoncalves/laravel-mailchimp/blob/main/README.md Error handling: catch MailchimpException and log the message and error body. ```php use JeffersonGoncalves\Mailchimp\Exceptions\MailchimpException; try { Mailchimp::campaigns()->send('c1'); } catch (MailchimpException $e) { logger()->error($e->getMessage(), $e->errorBody()); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.