2017 © Pedro Peláez
 

library mailchimp-api-php-client

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

image

classy-org/mailchimp-api-php-client

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

  • Friday, December 9, 2016
  • by PGBI
  • Repository
  • 24 Watchers
  • 2 Stars
  • 4,607 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 11 % Grown

The README.md

Mailchimp API php client

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0, (*1)

Installation

The Mailchimp API php client can be installed with Composer:, (*2)

composer require classy-org/mailchimp-api-php-client

Be sure you included composer autoloader in your app:, (*3)

require_once '/path/to/your/project/vendor/autoload.php';

Usage

// Instantiate the client
$client = new \Classy\MailchimpClient('dc834647d7f8a38c86b25dd4fdeff6f7-us2'); // use your mailchimp API key here

// Fetches your mailchimp lists
$httpResponse = $client->get('/lists');
$lists = json_decode($httpResponse->getBody()->getContents());

// Or shorter:
$lists = $client->getData('/lists');

Exception handling

This client is using Guzzle Http client. Exceptions are thrown when the Http response is not a 200 (OK) one:, (*4)

try {
    $response = $client->get('/lists/e87ab1c34');
} catch (Exception $e) {
    if ($e instanceof \GuzzleHttp\Exception\ConnectException) {
        // there was a networking error
    }

    if ($e instanceof \GuzzleHttp\Exception\ClientException) {
        // Mailchimp API returned a 4xx response.
        $httpStatusCode = $e->getCode();
        if ($httpStatusCode == 404) {
            // resource doesn't exist
        }
        if ($httpStatusCode == 401) {
            // you're unauthorized (api key must be invalid)
        }
        if ($httpStatusCode == 403) {
            // you're not allowed to request this endpoint
        }
        if ($httpStatusCode == 400) {
            // body payload is invalid
        }
        if (...) {
            //
        }

        $bodyResponse = $e->getResponse()->getBody()->getContents();
    }

    if ($e instanceof \GuzzleHttp\Exception\ServerException) {
        // Mailchimp returned a 5xx response, which means they experience technical difficulties.
    }
}

The Versions

09/12 2016

dev-master

9999999-dev

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

  Sources   Download

The Requires

 

by Avatar PGBI

09/12 2016

1.0.2

1.0.2.0

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

  Sources   Download

The Requires

 

by Avatar PGBI

08/11 2016

1.0.1

1.0.1.0

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

  Sources   Download

The Requires

 

by Avatar PGBI

31/10 2016

1.0.0

1.0.0.0

Simple wrapper around Guzzle Http Client to interact with Mailchimp API v3.0

  Sources   Download

The Requires

 

by Avatar PGBI