Trying to update a ca

Mar 8, 2011 at 6:12 AM

I am trying to create an email based on a template I have saved into mailchimp

            var apiKey = "mykey";
            var api = new MCApi(apiKey, false);
            var listID = "listid";
            var templates = MailChimpHelper.AvailableTemplates();
            var actualTemplate = templates.Where(t => t.Name == "Default News Letter").First();
            var templateID = actualTemplate.ID;//TODO:Add default title somewhere easier to change

            var option = new Campaign.Options(listID, "API Email", "", "Hello there", "ToName")
                             {TemplateID = new FSharpOption<int>(templateID)};

            var template = new Campaign.Content.Template();
            string cid = api.CampaignCreate(Campaign.Type.Regular, option,template);
            var c = api.CampaignTemplateContent(cid);
            c["content_1"] = @"<div>Here is some content inserted</div>";
            //api.CampaignUpdate(cid,"html", c);
            string[] testemails = new string[]{""};

How can I insert my own html into a template that is already created using the api?


Any tips would be great

Mar 8, 2011 at 7:43 AM

Check the "capmaignCreate" method:


When creating template campaign, U should provide its content:


var template = new Campaign.Content.Template();

template.Header = "<b>This is my header</b>";

template.Main = ".........................";

template.Footer = "......................";

template.Sidecolumn = "............";

Mar 8, 2011 at 8:59 AM

Cheers denisk,

Yes I did give that a try orginally without to much luck at all.

The email is not rendering any of the template. Where in the email is Header,Main,Footer & SideColumn?



Mar 8, 2011 at 9:15 AM
Edited Mar 8, 2011 at 9:21 AM

try "CampaignTemplateContent". It returns dictionary where keys are template sections (footer, header etc)

Pls, post the result...

Mar 8, 2011 at 10:32 PM

SO if I use var c = api.CampaignTemplateContent(cid); your right I get returned a dictionary of the keys.

So if I do a simple update like c["content_1"] = "YIP CHANGED"; it updates the dictionary as I want however if I send a test email the change doesnt appear. I assume that's because I haven't saved the changes back to mailchimp. I have looked at the api for CampaignTemplateContent and still cant get it.

I am looking trying  api.CampaignUpdate(cid, name, c);

From the api

"the parameter name ( see campaignCreate() ). For items in the options array, this will be that parameter's name (subject, from_email, etc.). Additional parameters will be that option name (content, segment_opts). "type_opts" will be the name of the type - rss, auto, trans, etc."

I'm been thick here I guess but what is the parameter "name"? what parameter is this? I think this is what I should be using to make the update.

Mar 9, 2011 at 10:19 AM
Edited Mar 9, 2011 at 10:20 AM

It seems I missed the issue of custom editable fields. Ufff...

So, as I understand U created template with editable field labeled "content_1" (more precisely - mc:edit = "content_1"). And now U want to update some campaign that uses this template. Right?


I added custom sections field in Content.Template class.

So U can use this:


var template = new Campaign.Content.Template();

template.Header = "<b>This is my header</b>";


template.CustomSections.Add("content_1", "YIP CHANGED");

api.CampaignUpdate(cid,"content", template);



If instead U want to update an existing content, use the following: 



 var c = api.CampaignTemplateContent(cid); // now this return Content.Template class

c.CustomSection["content_1"] =  "YIP CHANGED";

api.CampaignUpdate(cid,"content", c);


// Note that "CampaignTemplateContent" method returns only template sections without "Text" property.



Let me know if this works for U...

Mar 9, 2011 at 10:41 AM

awesome work denisk! that works a treat!!

I need to learn f# to see how you did it :)