Coder Social home page Coder Social logo

mailchimp-api-v3's Introduction

Mailchimp API v3 Build Status

Simple PHP wrapper for Mailchimp API v3.

You should read through Mailchimp's API v3 documentation (I know, it's pretty rough. Should get better soon.). To find out which resources you can request, take a look at the JSON API Schema for Mailchimp.

NOTE: All queries will return an instance of the Illuminate\Support\Collection object, which is really easy to work with. If you don't want to use the Collection object though, you can transform it into an array using $result->toArray().

Install

Add the following to your composer.json

{
    "require": {
        "pacely/mailchimp-apiv3": "dev-master"
    }
}

Usage

You are provided with one method:

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

Example

$mc = new Mailchimp('<api-key>');

$lists = $mc->request('lists', [
    'fields' => 'lists.id,lists.name,lists.stats.member_count',
    'count' => 30
]);

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

var_dump($lists); // object(Illuminate\Support\Collection)
var_dump($lists->toArray()); // array(10) { ... }
var_dump($lists->first()); // Returns the first item
var_dump($lists->take(3)); // Returns 3 items
var_dump($lists->toJson()); // Returns a JSON string

You can use a simple foreach/for loop or use the built in each(callable $callback) provided by our Collection object to loop through your items.

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

There's alot more you can do with the Collection object.

mailchimp-api-v3's People

Contributors

chrisrm avatar

Watchers

James Cloos avatar Rodrigo Bendia avatar

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.