Update the EMail Lists associated with a campaign

Highlighted
Occasional Contributor

Update the EMail Lists associated with a campaign

Hello

 

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();
campaign.ContactLists.Add(contactList);
}
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

2 REPLIES 2
Highlighted
CTCT Employee

Re: Update the EMail Lists associated with a campaign

Hi,

 

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

Highlighted
CTCT Employee

Re: Update the EMail Lists associated with a campaign

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
            campaign.ContactLists.Add(myList);
            
            //Update Campaign
            Utility.UpdateEmailCampaign(authdata, campaign);

 

 

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Constant Contact would like to hear from you

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured