Update the EMail Lists associated with a campaign

Occasional Participant

Update the EMail Lists associated with a campaign



I'm using the 'Utility.UpdateEmailCampaign' class to try and update EMail Lists associated with a campaign. I don't want to change anything else. The campaign is in 'DRAFT' status.


My code is (C#);


List<string> lEMailList = new List<string>(xEMailList);  // xEMailList will be "1,2,3" etc . . .  the Ids of the List(s)
EmailCampaign campaign;
campaign = Utility.GetEmailCampaignById(this.AuthenticationData, sECID); // sECID is my Campaign Id
campaign.ID = sECID;
for (int i = 0; i < lEMailList.Count; i++)
ContactList contactList = new ContactList();
contactList.Id = lEMailList[i].ToString();
Utility.UpdateEmailCampaign(this.AuthenticationData, campaign);


I get "Object reference not set to an instance of an object."


If a then add;


campaign.EmailContentFormat = "HTML";


I get a different error;


I get "The remote server returned an error: (400) Bad Request."


How do I just update EMail Lists against campaigns?????????


Thank You




This is just a quick update to let you know that we are working on troubleshooting why this is happening for you, and we will get back to you here about it.


I just didn't want you to think we were ignoring this post.



Best Regards,

Shannon W.

API Support Specialist

Hi again,


It seems that the wrapper wasn't encoding properly.  The HTML and text content should be encoded as below (which the wrapper should be handling, but doesn't seem to be).  Do make sure you're using the most recent version of our .NET wrapper here also if you still get errors.


ConstantContactBO.Entities.EmailCampaign campaign = Utility.GetEmailCampaignById(authdata, EmailID);

            //Check to see if this email has any ContactLists set.  If null, create it
            if (campaign.ContactLists == null)
                campaign.ContactLists = new List<ContactList>();

            //Set campaign nodes with missing information - Begin
            campaign.Content = HttpUtility.HtmlEncode(campaign.Content);
            campaign.TextContent = HttpUtility.HtmlEncode(campaign.TextContent);
            //Set campaign nodes with missing information - End

            //Create now List with an ID of 1
            ContactList myList = new ContactList("1");

            //Add List to ContactLists of Campaign
            //Update Campaign
            Utility.UpdateEmailCampaign(authdata, campaign);




Best Regards,

Shannon W.

API Support Specialist

Developer Portal

View API documentation, code samples, get your API key.

Visit Page