PHP code example of testudio / mailchimp-marketing

1. Go to this page and download the library: Download testudio/mailchimp-marketing 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/ */

    

testudio / mailchimp-marketing example snippets






$mailchimp = new MailchimpMarketing\ApiClient();

$mailchimp->setConfig([
  'apiKey' => 'YOUR_API_KEY',
  'server' => 'YOUR_SERVER_PREFIX'
]);

$response = $mailchimp->ping->get();
print_r($response);

$mailchimp->setConfig([
  'apiKey' => 'YOUR_API_KEY',
  'server' => 'YOUR_SERVER_PREFIX'
]);

$mailchimp->setConfig([
  'accessToken' => 'YOUR_ACCESS_TOKEN',
  'server' => 'YOUR_SERVER_PREFIX'
]);

git clone [email protected]:testudio/mailchimp-marketing-php.git

$response = $mailchimp->lists->getAllLists();
foreach ($response->lists as $list) {
  $list_id = $list->id;
  $list_name = $list->name;
  ...
}

$response = $mailchimp->lists->getListInterestCategories($list_id);
foreach ($response->categories as $category) {
  $category_id = $category->id;
  $category_title = $category->title;
  ...
}

$list_id = '7f4f516be';
// Load up to 10 tags.
$response = $mailchimp->lists->listSegments($list_id);
// Load up to 200 tags.
$response = $mailchimp->lists->listSegments($list_id, NULL, NULL, '200');
if ($response) {
  foreach ($response->segments as $segment) {
    $segment_id = $segment->id;
    $segment_name = $segment->name;
    $segment_member_count = $segment->member_count;
    $segment_list_id = $segment->list_id;
  }
}