Editing Groups - within a list through .Net API

Jun 23, 2010 at 10:44 PM

Hello all,

I have a question. I have a list on my Mailchimp account. This list has a few groups.
I am using the .Net API to add new users to my Mailchimp list.
While adding these users I want to add them to a few of these groups as well.
What functionality of the API do I use to achieve this ?

I read through all the documentation available and couldn't find anything.
I really need this to get my project going. Any help will be highly appreciated.


Jun 24, 2010 at 3:30 PM

Hi Ronak,

The wrapper provides the same functionality as the MailChimp Api -- the caveat there is with the exception of the last update announcement by MailChimp regarding the grouping changes, but that's in the works with a beta in a week or so. I'm afraid I got slammed with a last minute eGift-card to Netsuite integration before Father's Day otherwise it'd be done by now.

Anyway, if you look at the MC online docs you'll see that interest groups are assigned through the merge-vars using the special field name "INTERESTS", so the code could go something like this....

         listSubscribeInput input = new listSubscribeInput();
         // any directive overrides 
         input.api_Validate = false;
         input.api_AccessType = EnumValues.AccessType.Serial;
         input.api_OutputType = EnumValues.OutputType.JSON;
         // method parameters
         input.apikey = apikey;
         input.id = listid;
         input.double_optin = false;
         input.replace_interests = true;
         input.update_existing = true;
         input.email_address = "zzz@dbm.com";
         input.email_type = EnumValues.emailType.html;
         Dictionary<string, object> mvars = new Dictionary<string, object>();
         mvars.Add( "FNAME", "First" );
         mvars.Add( "LNAME", "Last-Name" );
         mvars.Add( "INTERESTS", "Integration, Surveys" );
         input.merge_vars = mvars;

         // execution
         listSubscribe cmd = new listSubscribe( input );
         listSubscribeOutput output = cmd.Execute();

         // output, format with user control
         if ( output.api_ErrorMessages.Count > 0 )
            showResults( output.api_Request, output.api_Response,     // raw data	
            output.api_ErrorMessages, output.api_ValidatorMessages ); // & errors
            show_result( output.result );

Jun 24, 2010 at 9:28 PM

Hey David,

Thanks a lot for the quick reply. This new feature coming out in the beta version will help me complete my project.
I will look forward to the new beta version coming out hopefully next week. 

Thanks again,



Jun 24, 2010 at 11:08 PM

You can do the example above right now -- that's what was done when there was only a single interest group, and will still work like that, acting against the first or default grouping.

However multiple groupings aren't supported.

As MailChimp puts it --  Groupings are groups of interest groups.

So as long as you can stick to one single level grouping it should work fine -- if not, then unfortunately you'll have to wait for the beta.




Apr 28, 2011 at 9:51 PM

Hi there,

I am also new to using the Mail Chimp API. Just confirming that the code above will allow me to add a new subscriber to a particular Interest Group?

May 6, 2011 at 12:47 AM
Edited May 6, 2011 at 12:47 AM

I would no longer use the "INTERESTS" special group.

Review the MC documentation, and use the Groupings type methods.

So add Groupings & Groups to your list, and then either subscribe, or update existing subscribers, assigned to the groups.

It seems a bit crazy/complex the first couple times - but play with it on a test list and view it in the web app, and it'll become clearer.

Of course, some of us just use static segment wherever possible so we don't have to think about it. :-)


Jul 27, 2012 at 10:51 PM
Edited Jul 27, 2012 at 10:51 PM

Is there an update to how this currently works? I'm having difficulty building the "merge_vars" object.

            Dictionary<string, string> thisGroup = new Dictionary<string,string>();
            //thisGroup.Add("id", GroupingID.ToString()); //neither option id nor name works
            thisGroup.Add("name", "My Interest Grouping Name");
            thisGroup.Add("groups", "Interest 1, Interest 2");

            List<object> groupings = new List<object>();

            Dictionary<string, object> merge_vars = new Dictionary<string,object>();
            merge_vars.Add("GROUPINGS", groupings);

Error message in listMemberUpdateOutput:

+ [0] {Error Code: ex, Message: Object reference not set to an instance of an object.

   at PerceptiveMCAPI.apiXmlRpc.FormatMemberMergeVars(Dictionary`2 merge_vars)   at PerceptiveMCAPI.Methods.listUpdateMember.ExecuteXmlRpc()} PerceptiveMCAPI.Types.Api_Error

Jul 30, 2012 at 9:30 PM

If anyone comes looking for the answer, here's working code, adapted from a StackOverflow answer.



//now we need to assign this Interest Group to all matching subscribers
List<string> myInterestGroups = new List<string>();

List<interestGroupings> groupings = new List<interestGroupings>();
groupings.Add(new interestGroupings { id = GroupingID, groups = myInterestGroups });

Dictionary<string, object> merge_vars = new Dictionary<string,object>();
merge_vars.Add("GROUPINGS", groupings);
listUpdateMemberInput updateMemberInput = new listUpdateMemberInput();

listUpdateMemberParms memberParms = new listUpdateMemberParms();
memberParms.apikey = MCAPISettings.default_apikey;
memberParms.id = ListID;
memberParms.merge_vars = merge_vars;

listUpdateMember updateMember = new listUpdateMember();
foreach (Subscriber member in pressrelease.Recipients)
    memberParms.email_address = member.Email;
    updateMemberInput.parms = memberParms;

    listUpdateMemberOutput updateMemberOutput = updateMember.Execute(updateMemberInput);