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 -

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

Below are the GoDoc references for each supported resource:

Lists -
Lists/Members -


Fetch the package from GitHub:

go get

Import to your project:

import mailchimp ""

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

import ""


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

Set API Key

First, set your MailChimp API key:

import mailchimp ""
err := mailchimp.SetKey("YOUR-API-KEY")
Create a list
import ""

// 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: "",
		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 ""

// Set request parameters.
params := &members.NewParams{
	EmailAddress: "",
	Status:       members.StatusSubscribed,

// Add member to list 123456.
member, err := members.New("123456", params)
fmt.Printf("%+v\n", member)
Get list members
import ""

// 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 ""

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

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


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 ./...


The Go Devs - For existing
Discord Gophers (Join Chat) - Troubleshooting and advice
go-querystring ( - Query string library
Choly ( - custom JSON solution

Expand ▾ Collapse ▴



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


See or visit for more info.



This section is empty.


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")


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.


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.


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.