PHP code example of pacely / mailchimp-apiv3

1. Go to this page and download the library: Download pacely/mailchimp-apiv3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pacely / mailchimp-apiv3 example snippets


// config/app.php
'providers' => [
    ...
    Mailchimp\MailchimpServiceProvider::class
]

// config/app.php
'aliases' => [
    ...
    'MC' => Mailchimp\MailchimpFacade::class
]



return [

    /*
    |--------------------------------------------------------------------------
    | Mailchimp API key
    |--------------------------------------------------------------------------
    |
    | To obtain an API key, go to mailchimp.com under your profile
    | you will find Extras -> API keys. Paste the key below.
    |
    */
    'apikey' => ''
];

request($resource, $arguments = [], $method = 'GET') // $arguments is used as POST data or GET parameters, depending on the method used.

get($resource, array $options = [])
head($resource, array $options = [])
put($resource, array $options = [])
post($resource, array $options = [])
patch($resource, array $options = [])
delete($resource, array $options = [])

$mc = new Mailchimp('<api-key>', '<guzzle-options[array]>');

// Get 10 lists starting from offset 10 and fset' => 10,
    'count' => 10
]);

// Will fire this query: 
// GET https://us1.api.mailchimp.com/3.0/lists?fields=lists.id,lists.name,lists.stats.member_count&count=10

// Returns object(Illuminate\Support\Collection)
var_dump($result);

// Returns the first item
var_dump($result->first());

// Returns 3 items
var_dump($result->take(3));

// Returns a JSON string
var_dump($result->toJson());

// Returns an array
var_dump($result->toArray());

$result->each(function ($item) {
    echo $item['name'].' ('.$item['stats']['member_count'].')'.PHP_EOL;
});

// All these fields are sts', [
    'name' => 'New list',
    'permission_reminder' => 'You signed up for updates on Greeks economy.',
    'email_type_option' => false,
    'contact' => [
        'company' => 'Doe Ltd.',
		'address1' => 'DoeStreet 1',
		'address2' => '',
		'city' => 'Doesy',
		'state' => 'Doedoe',
		'zip' => '1672-12',
		'country' => 'US',
		'phone' => '55533344412'
    ],
    'campaign_defaults' => [
        'from_name' => 'John Doe',
        'from_email' => '[email protected]',
        'subject' => 'My new campaign!',
        'language' => 'US'
    ]
]);

$result = $mc->get('lists/e04d611199', [
    'fields' => 'id,name,stats.member_count'
]);

$mc->setProxy('https://127.0.0.1', 10, true, 'username', 'password');

$result = $mc->get('lists/e04d611199', [
    'fields' => 'id,name,stats.member_count'
]);