GithubHelp home page GithubHelp logo

adrian7 / mailchimp-api-v3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonathanwkelly/mailchimp-api-v3

0.0 1.0 0.0 34 KB

API client for MailChimp API v3

License: MIT License

PHP 100.00%
mailchimp-api php-mailchimp mailchimp-api-v3 mailchimp-api-wrapper

mailchimp-api-v3's Introduction

PHP Wrapper for MailChimp API v3 CircleCI

Installation

composer require adrian7/mailchimp-api-v3

Usage

There's one method to rule them all:

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

But its clever enough to map these calls aswell:

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

Pagination

We use offset and count in the query string to paginate data, because it provides greater control over how you view your data. Offset defaults to 0, so if you use offset=1, you'll miss the first element in the dataset. Count defaults to 10.

Source: http://kb.mailchimp.com/api/article/api-3-overview

Filtering

Most endpoints don't currently support filtering, but we plan to add these capabilities over time. Schemas will tell you which collections can be filtered, and what to include in your query string.

Source: http://kb.mailchimp.com/api/article/api-3-overview

Partial Response

To cut down on data transfers, pass a comma separated list of fields to include or exclude from a certain response in the query string. The parameters fields and exclude_fields are mutually exclusive and will throw an error if a field isn't valid in your request.

Source: http://kb.mailchimp.com/api/article/api-3-overview

Behind Proxy

If you are behind a proxy, you can use setProxy directly on the class.

setProxy(host : string, port : int, [ssl : bool = false], [username = null], [password = null]);

See the example.

Examples

All queries will return an object containing the parsed json response.

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

// Get 10 lists starting from offset 10 and include only a specific set of fields
$result = $mc->request('lists', [
    'fields' => 'lists.id,lists.name,lists.stats.member_count',
    'offset' => 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

var_dump($result);

Create list

// All these fields are required to create a new list.
$result = $mc->post('lists', [
    'name' => 'New list',
    'permission_reminder' => 'You signed up for updates on mailchimp-api-v3.',
    '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'
    ]
]);

Subresources

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

Proxy

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

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

Further documentation

You should read through Mailchimp's API v3 documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.