GithubHelp home page GithubHelp logo

mailchimp.net's Introduction

MailChimp.NET

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

Build status

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;

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);
	}
}

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)

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.