• This repository has been archived on 24/Mar/2023
  • Stars
    star
    178
  • Rank 213,978 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✉️ .NET Wrapper for the MailChimp v2.0 API

MailChimp.NET Build status deprecated

.NET Wrapper for the MailChimp v2.0 API, built with MailChimp love ❤️

Note: This is for the 2.0 API (which is now deprecated). If you'd like a client for the 3.0 API, check out this one by Brandon Seydel

Quick Start

Install the NuGet package from the package manager console:

Install-Package MailChimp.NET

Next, you will need to provide MailChimp.NET with your API key in code. Need help finding your API key? Check here: http://kb.mailchimp.com/article/where-can-i-find-my-api-key

In your application, call:

// Pass the API key on the constructor:
MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");

// Next, make any API call you'd like:
ListResult lists = mc.GetLists();

Getting help

For help and support, first check out the examples below.

If you can't figure out what you need from the examples (or if you're running into a tough problem) you might want to check out the MailChimp support site, or ping the MailChimp API support twitter account.

If you've got a question/bug/feature request for the API wrapper itself, please use Github issues and consider contributing to the project yourself. See the "Making contributions" section for more information on how to contribute.

Examples

Getting the first 100 users in each list:
using MailChimp;
using MailChimp.Lists;
using MailChimp.Helper;

MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");
ListResult lists = mc.GetLists();

//  For each list
foreach(var list in lists.Data)
{
    //  Write out the list name:
	Debug.WriteLine("Users for the list " + list.Name);
	
	//  Get the first 100 members of each list:
	MembersResult results = mc.GetAllMembersForList(list.Id, "subscribed", 0, 100);
	
	//  Write out each member's email address:
	foreach(var member in results.Data)
	{
	    Debug.WriteLine(member.Email);
	}
}
Subscribe an email address to a list:
MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");

//	Create the email parameter
EmailParameter email = new EmailParameter()
{
	Email = "[email protected]"
};

EmailParameter results = mc.Subscribe("YourListID", email);
Subscribe an email address to a list and set their interest groups (custom merge variables):
// optionally create a class that inherits MergeVar and add any additional merge variable fields:
[System.Runtime.Serialization.DataContract]
public class MyMergeVar : MergeVar
{
	[System.Runtime.Serialization.DataMember(Name = "FNAME")]
	public string FirstName { get; set; }
	[System.Runtime.Serialization.DataMember(Name = "LNAME")]
	public string LastName { get; set; }
}

MyMergeVar myMergeVars = new MyMergeVar();
myMergeVars.Groupings = new List<Grouping>();
myMergeVars.Groupings.Add(new Grouping());
myMergeVars.Groupings[0].Id = 1234; // replace with your grouping id
myMergeVars.Groupings[0].GroupNames = new List<string>();
myMergeVars.Groupings[0].GroupNames.Add("Your Group Name");
myMergeVars.FirstName = "Testy";
myMergeVars.LastName = "Testerson";

MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");

//	Create the email parameter
EmailParameter email = new EmailParameter()
{
	Email = "customeremail@righthere.com"
};

EmailParameter results = mc.Subscribe("YourListID", email, myMergeVars);

// or use the Dictionary to specify the fields and values. 
// GetMemberInfo will always return the fields and values using the dictionary and not the custom class.
MergeVar myMergeVars = new MergeVar();
myMergeVars.Groupings = new List<Grouping>();
myMergeVars.Groupings.Add(new Grouping());
myMergeVars.Groupings[0].Id = 1234; // replace with your grouping id
myMergeVars.Groupings[0].GroupNames = new List<string>();
myMergeVars.Groupings[0].GroupNames.Add("Your Group Name");
myMergeVars.Add("FNAME", "Testy");
myMergeVars.Add("LNAME", "Testerson");

MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");

//	Create the email parameter
EmailParameter email = new EmailParameter()
{
	Email = "customeremail@righthere.com"
};

EmailParameter results = mc.Subscribe("YourListID", email, myMergeVars);
Getting location data for each list:
MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");
ListResult lists = mc.GetLists();

//  For each list
foreach(var list in lists.Data)
{
	Debug.WriteLine("Information for " + list.Name);
	
	//  Get the location data for each list:
	List<SubscriberLocation> locations = mc.GetLocationsForList(list.Id);
	
	//  Write out each of the locations:
	foreach(var location in locations)
	{
	    Debug.WriteLine("Country: {0} - {2} users, accounts for {1}% of list subscribers", location.Country, location.Percent, location.Total);
	}
}

Mocking

The IMailChimpManager and IMailChimpExportManager interfaces have been included to allow you to easily mock this API for your own testing.

To set up in your dependency injector, bind the interface with a constructor argument passing your API key. This example uses Ninject loading the value from an app setting in the Web.config named 'MailChimpApiKey':

kernel.Bind<IMailChimpManager>()
	.To<MailChimpManager>()
	.WithConstructorArgument("apiKey", ConfigurationManager.AppSettings["MailChimpApiKey"]);

If you were to use a framework like Moq you might write something like:

public class ThingThatDependsOnMailChimpManager{
	IMailChimpManager _mailChimpManager;

	public ThingThatDependsOnMailChimpManager(IMailChimpManager mailChimpManager){
		_mailChimpManager = mailChimpManager;
	}

	public bool DoSomething(){
		_mailChimpManager.UpdateCampaign("campaignId", "name", new object());
		return true;
	}
}
// Arrange
Mock<IMailChimpManager> mailChimpManagerMock = new Mock<IMailChimpManager>();

mailChimpManagerMock.Setup(x => x.UpdateCampaign(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object>())
.Return(new CampaignUpdateResult());

// Act
var thing = new ThingThatDependsOnMailChimpManager(mailChimpManagerMock.Object);
var result = thing.DoSomething();

// Assert
Assert.IsTrue(result);

Making contributions

This project is not affiliated with MailChimp. All contributors to this project are unpaid average folks (just like you!) who choose to volunteer their time. If you like MailChimp and want to contribute, we would appreciate your help! To get started, just fork the repo, make your changes and submit a pull request.

Also: If you're reading this and you're from MailChimp, we wouldn't mind some swag.

Status

Here is the progress so far (according to the MailChimp API docs ) :

Overall: 71% (85 of 120)

More Repositories

1

OWIN-WebAPI-Service

✅ OWIN / WebAPI windows service example. Includes attribute based routing sample
C#
202
star
2

influxdb-ui

🐎 A simple UI for InfluxDB
JavaScript
127
star
3

domainname-parser

🏬 .NET domain name parsing library (uses publicsuffix.org)
C#
32
star
4

Halloweenfire

🎃 Arduino sketch for multiple neopixels to create spooky 'fire' effect
C++
30
star
5

Pushover.NET

📣 .NET Wrapper for the Pushover API
C#
27
star
6

iTunesSearch

🎵 A .NET wrapper to the iTunes search API
C#
23
star
7

consul-api

🚠 C# API client for Consul
C#
23
star
8

net-version

🔍 .NET version checker written in Go
Go
18
star
9

calendar-service

📅 A microservice to return Google calendar events in JSON format
Go
12
star
10

InfluxClient

🌊 A .NET InfluxDB client
C#
11
star
11

NLogReader

🔦 NLog dashboard for centralized loggging, searching and filtering
C#
9
star
12

feature

🌱 Feature flag helpers for .NET
C#
7
star
13

HalloweenNeoSpookyEyes

👀 Halloween spooky blinking eyes with neopixels
Arduino
2
star
14

appliance-monitor

🔔 Monitoring and notification system for laundry machines, dishwashers and other non-connected appliances
Go
2
star
15

iamserver

🔐 Identity and Access management server with built-in UI
Go
2
star
16

plex2slack-lambda

🔔 Plex events => AWS Lambda => Slack notification
Go
2
star
17

tvdb

📺 TVDB v2.0 API wrapper for Go
Go
2
star
18

HalloweenRingFire

🔥 Arduino code using a Neopixel ring with a fire effect
Arduino
2
star
19

tvshow-info

A .NET class library for getting information about a TV show episode
C#
2
star
20

twitter-breaking-news

:squirrel: Simple breaking news microservice written in Go
Go
2
star
21

knopeannisms

🌻 Compliment generator. Similar to Leslie Knope compliments for Ann Perkins
JavaScript
2
star
22

nws-alerts

⛅ AWS Lambda based API service for National Weather Alerts
Go
1
star
23

embd

Repository for embd based sensors
Go
1
star
24

pollen

🌻 AWS Lambda based API service to get pollen forecast for a given zipcode
Go
1
star
25

CircuitPlaygroundFire

🎃 Arduino sketch to create spooky 'fire' effect for Adafruit Circuit Playground using the onboard neopixels
C++
1
star
26

tplink-logger

🔌 InfluxDB logger for the HS110 energy monitoring outlet
Go
1
star
27

daydash

🔮 A service to host and provide remote administration for the Dashboard UI
Go
1
star
28

fxaudio

⏯️ REST service for multichannel audio on demand from Raspberry Pi
Go
1
star
29

plexbot

🔀 Simple app to help organize tv shows into the Plex naming format
Go
1
star
30

fxtrigger

🔂 REST service for Raspberry Pi GPIO/Sensor -> webhooks
Go
1
star
31

PatchMaker

Console based directory compare and patch maker
C#
1
star
32

influx-annotate

Command line tool to add annotations to an InfluxDB database
Go
1
star