Constant Contact - Update Contact - Server 500 Error

SOLVED
Go to solution
VC1977
Regular Participant

Constant Contact - Update Contact - Server 500 Error

Hi,

 

I am trying to update a contact which already exists in my list by usingUtility.UpdateContactFullForm(authenticationData, contact);

 

However, I get an error message stating: The remote server returned an error: (500) Internal Server Error.

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

 

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 

I have referenced the ConstantContactBO.dll and the ConstantContactUtility;

I can't seem to figure out the problem, any help is much appreciated. Thanks.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ConstantContactBO;
using ConstantContactUtility;


public partial class hmm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string nextChunkId;
Contact contact = new Contact();
//Authentication Data
AuthenticationData authenticationData = new AuthenticationData();
authenticationData.Username = "xxxxxxx";
authenticationData.Password = "xxxxxx";
authenticationData.ApiKey = "xxxxxxxx";

// get user Contact List collection
IList<ContactList> lists = Utility.GetUserContactListCollection(authenticationData, out nextChunkId);

//Search for Contact By Email
string x = "a@a.com";
string[] emailAddress = new string[] { x.Trim() };
IList<Contact> myList = Utility.SearchContactByEmail(authenticationData, emailAddress, out nextChunkId);

for (int i = 0; i < myList.Count; i++)
{
contact.Id = myList[0].Id;
contact.FirstName = Server.HtmlEncode("Souj");
contact.LastName = Server.HtmlEncode("Gajjala");
contact.EmailAddress = Server.HtmlEncode("a@a.com");

ContactOptInList theList = new ContactOptInList();
theList.OptInSource = ContactOptSource.ActionByContact;
theList.ContactList = new ContactList("39");
contact.ContactLists.Add(theList);
Utility.UpdateContactFullForm(authenticationData, contact);
}


}
}

 

 

 

 

1 ACCEPTED SOLUTION
Shannon_W
Employee

Hi,

 

Unless I'm missing it, it looks like you are just missing the step where you search for the contact by their ID (after you search for them by email address.  You can see how I handle that below:

 

//Get contact by Email
string _nextChunk; List<string> email = new List<string>(); email.Add("test@test.com"); IList<Contact> myContact = Utility.SearchContactByEmail(authdata, email, out _nextChunk); //Get Contact by ID Contact thisContact = Utility.GetContactDetailsById(authdata, myContact[0].Id); //Change contact properties Utility.RemoveContactFromAllLists(authdata, myContact[0].Id); thisContact.OptInSource = ContactOptSource.ActionByCustomer; thisContact.Status = ContactStatus.Active; //Add Lists ContactOptInList newList = new ContactOptInList(); newList.ContactList = new ContactList("1"); //Contact list you want to add them to thisContact.ContactLists.Add(newList); //Update contact Utility.UpdateContactFullForm(authdata, thisContact);

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

2 REPLIES 2
Shannon_W
Employee

Hi,

 

Unless I'm missing it, it looks like you are just missing the step where you search for the contact by their ID (after you search for them by email address.  You can see how I handle that below:

 

//Get contact by Email
string _nextChunk; List<string> email = new List<string>(); email.Add("test@test.com"); IList<Contact> myContact = Utility.SearchContactByEmail(authdata, email, out _nextChunk); //Get Contact by ID Contact thisContact = Utility.GetContactDetailsById(authdata, myContact[0].Id); //Change contact properties Utility.RemoveContactFromAllLists(authdata, myContact[0].Id); thisContact.OptInSource = ContactOptSource.ActionByCustomer; thisContact.Status = ContactStatus.Active; //Add Lists ContactOptInList newList = new ContactOptInList(); newList.ContactList = new ContactList("1"); //Contact list you want to add them to thisContact.ContactLists.Add(newList); //Update contact Utility.UpdateContactFullForm(authdata, thisContact);

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

VC1977
Regular Participant

Thanks Shannon! That was very helpful and yes I did miss out the //Get Contact By Id

 
Developer Portal

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

Visit Page