使用c#通过api v2.0向Mailchimp订阅者组添加值

时间:2014-01-21 15:26:49

标签: c# mailchimp

我在mailchimp中设置了一个名为“Location”的组,我希望使用带有c#的api和json为每个订阅者填充一个字符串。我尝试了很多东西,但我总是得到一个内部服务器错误500虽然我已成功设法订阅用户到列表所以我知道api正在使用我的设置。我认为问题在于我添加组的方式,但我不知道它是什么。

 var url = https://us7.api.mailchimp.com/2.0/lists/subscribe.json

        using (var client = new WebClient())
        {
            Dictionary<string, object> data = new Dictionary<string, object>();
            Dictionary<string, string> merge_vars = new Dictionary<string, string>();
            Dictionary<string, string> groupings = new Dictionary<string, string>();
            Dictionary<string, string> groups = new Dictionary<string, string>();

            data.Add("apikey", ApiKey);
            data.Add("id", ListId);
            data.Add("email", email);

            groups.Add("Location", "Test");
            groupings.Add("groups", JsonConvert.SerializeObject(groups));
            merge_vars.Add("groupings", JsonConvert.SerializeObject(groupings));
            data.Add("merge_vars", JsonConvert.SerializeObject(merge_vars));

            var resp = JsonConvert.DeserializeObject<MailChimpMemberListsResponse>(client.UploadString(url, JsonConvert.SerializeObject(data)));


        }

0 个答案:

没有答案