MailChimp MCAPI.NET - 订阅分组

时间:2013-07-19 20:25:46

标签: c# .net mailchimp mcapi.net

我正在使用MCAPI.NET与MailChimp连接,我需要指定订阅的分组。

        string emailAddr = "somebody@somewhere.net";
        MailChimp.MCApi mc = new MailChimp.MCApi("myapikey", true);

        var merges = new MailChimp.Types.List.Merges();
        merges.Add("FNAME", "MyFirstName");
        merges.Add("LNAME", "MyLastName");

        var group = new string[]{"PSS"};
        var grp = new MailChimp.Types.List.Grouping("Staff Type", group);
        merges.Add("Groupings", grp);

        mc.ListSubscribe("mylistid", emailAddr, merges);

我的分组没有设定。有人有他们可以分享的工作实例吗?

1 个答案:

答案 0 :(得分:2)

您的代码存在的问题是您没有向merge var“Groupings”添加分组列表。值必须是以下类型:

MailChimp.Types.MCList<MailChimp.Types.List.Grouping>

这是一份工作副本:

var merges = new List.Merges();
var groupingList = new MailChimp.Types.MCList<MailChimp.Types.List.Grouping>();
var grouping = new MailChimp.Types.List.Grouping(myGroupId, new string[] { group1, group2 });
groupingList.Add(grouping);

merges["Groupings"] = groupingList;

// You may find it practical to include the following options, at least while testing the groupings
var options = new MailChimp.Types.List.SubscribeOptions();
options.DoubleOptIn = false;
options.ReplaceInterests = false;
options.SendWelcome = false;

mcapi.ListSubscribe(myMailChimpListId, email, merges, options);