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.
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
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"
At the moment, this library has minimal coverage of the MailChimp API.
First, set your MailChimp API key:
import mailchimp "github.com/beeker1121/mailchimp-go"
...
err := mailchimp.SetKey("YOUR-API-KEY")
...
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: "[email protected]",
Subject: "Newsletter",
Language: "en",
},
EmailTypeOption: false,
Visibility: lists.VisibilityPublic,
}
list, err := lists.New(params)
...
fmt.Printf("%+v\n", list)
import "github.com/beeker1121/mailchimp-go/lists/members"
...
// Set request parameters.
params := &members.NewParams{
EmailAddress: "[email protected]",
Status: members.StatusSubscribed,
}
// Add member to list 123456.
member, err := members.New("123456", params)
...
fmt.Printf("%+v\n", member)
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)
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)
import "github.com/beeker1121/mailchimp-go/lists/members"
...
// 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 (https://github.com/google/go-querystring) - Query string library
Choly (http://choly.ca/) - custom JSON solution