README

mailchimp-go License Go Report Card Build Status

mailchimp-go is a Go client for the MailChimp API v3.

While coverage of the MailChimp API is limited in the current state, the goal is to provide a basic structure that can be built upon to eventually have full coverage.

Contributing code to complete missing resources is greatly appreciated.

API GoDoc Reference

Below is the main mailchimp-go GoDoc reference:

mailchimp-go - http://godoc.org/github.com/beeker1121/mailchimp-go

Each API resource is a separate package within mailchimp-go.

Below are the GoDoc references for each supported resource:

Lists - https://godoc.org/github.com/beeker1121/mailchimp-go/lists
Lists/Members - https://godoc.org/github.com/beeker1121/mailchimp-go/lists/members

Installation

Fetch the package from GitHub:

go get github.com/beeker1121/mailchimp-go

Import to your project:

import mailchimp "github.com/beeker1121/mailchimp-go"

Import the API resources you wish to use. For example, to use the Lists resource:

import "github.com/beeker1121/mailchimp-go/lists"

Usage

At the moment, this library has minimal coverage of the MailChimp API.

Set API Key

First, set your MailChimp API key:

import mailchimp "github.com/beeker1121/mailchimp-go"
...
err := mailchimp.SetKey("YOUR-API-KEY")
...
Create a list
import "github.com/beeker1121/mailchimp-go/lists"
...

// Set request parameters.
params := &lists.NewParams{
	Name: "My List",
	Contact: &lists.Contact{
		Company:  "Acme Corp",
		Address1: "123 Main St",
		City:     "Chicago",
		State:    "IL",
		Zip:      "60613",
		Country:  "United States",
	},
	PermissionReminder: "You opted to receive updates on Acme Corp",
	CampaignDefaults: &lists.CampaignDefaults{
		FromName:  "John Doe",
		FromEmail: "newsletter@acmecorp.com",
		Subject:   "Newsletter",
		Language:  "en",
	},
	EmailTypeOption: false,
	Visibility:      lists.VisibilityPublic,
}

list, err := lists.New(params)
...
fmt.Printf("%+v\n", list)
Add a member to a list
import "github.com/beeker1121/mailchimp-go/lists/members"
...

// Set request parameters.
params := &members.NewParams{
	EmailAddress: "user@example.com",
	Status:       members.StatusSubscribed,
}

// Add member to list 123456.
member, err := members.New("123456", params)
...
fmt.Printf("%+v\n", member)
Get list members
import "github.com/beeker1121/mailchimp-go/lists/members"
...

// Set request parameters.
params := &members.GetParams{
	Status: members.StatusSubscribed,
}

// Get subscribed members of list 123456.
listMembers, err := members.Get("123456", params)
...
fmt.Printf("%+v\n", listMembers)
Get a list member
import "github.com/beeker1121/mailchimp-go/lists/members"
...

// Get member 123 from list 123456.
member, err := members.GetMember("123456", "123", nil)
...
fmt.Printf("%+v\n", member)
Delete a list member
import "github.com/beeker1121/mailchimp-go/lists/members"
...

// Delete member 123 from list 123456.
err := members.Delete("123456", "123")
...

Testing

To run the tests, you must have a valid MailChimp account and API key.

Set the API key environment variable:

export MAILCHIMP_API_KEY=your-key

Run the tests from the mailchimp-go directory:

go test -v ./...

Thanks

The Go Devs - For existing
Discord Gophers (Join Chat) - Troubleshooting and advice
go-querystring (https://github.com/google/go-querystring) - Query string library
Choly (http://choly.ca/) - custom JSON solution

Expand ▾ Collapse ▴

Documentation

Overview

Package mailchimp is a Go client for the MailChimp API v3.

Reference: http://developer.mailchimp.com/documentation/mailchimp/reference/overview/

See README.md or visit https://github.com/beeker1121/mailchimp-go for more info.

Index

Constants

This section is empty.

Variables

var (
	// ErrAPIKeyNotSet is returned when a call to the API is
	// attempted before the user set an API key.
	ErrAPIKeyNotSet = errors.New("mailchimp: API key has not been set")

	// ErrAPIKeyFormat is returned when the provided API key
	// is in an invalid format.
	ErrAPIKeyFormat = errors.New("mailchimp: Invalid API key format")
)

Functions

func Call

func Call(method, path string, queryParams, bodyParams, v interface{}) error

Call issues a request to the MailChimp API.

func SetClient

func SetClient(client *http.Client)

SetClient sets the http.Client used to make API requests.

func SetKey

func SetKey(apiKey string) error

SetKey sets the API key and updates the data center value accordingly.

Types

type APIError

type APIError struct {
	Type   string  `json:"type"`
	Title  string  `json:"title"`
	Status int     `json:"status"`
	Detail string  `json:"detail"`
	Errors []Error `json:"errors,omitempty"`
}

APIError defines the MailChimp API response error structure.

func (*APIError) Error

func (ae *APIError) Error() string

Error satisfies the error interface method.

type Error

type Error struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

Error defines a field error.

Directories

Path Synopsis
lists Package lists implements the Lists resource of the MailChimp API v3.
lists/members Package members implements the Members resource of the MailChimp API v3.
query Package query implements encoding of structs into URL query parameters.