Code in C# for Updating Contact List

tippua
Occasional Participant

Code in C# for Updating Contact List

Hi

 

Can any one kindly provide me the C# code for updating contact list, it's bit urgent i am confused, kindy reply ASAP, waiting for your reply,

 

regards, 

3 REPLIES 3
DaveBerard
Moderator

I would recommend leveraging our C# Wrapper Library to do your development work.  I'm replying to your post assuming you are going to use that Library and providing you the code snippets for creating a contact, updating a contact and moving a contact to Do Not Mail.  There are many other features of the library, most of which are easy to understand and use from just this short code snippet.  You can find the library here: http://community.constantcontact.com/t5/Documentation/Code-Samples/ba-p/25019

 

// Create an Authentication Data Object
AuthenticationData authdata = new AuthenticationData(ApiKey, Username, Password);

// Create a new Contact
Contact contact = new Contact();
contact.EmailAddress = "test@test.com";

// Get all the Contact Lists
string nextFiftyLists;
List<ContactList> contactLists = (List<ContactList>)Utility.GetUserContactListCollection(authdata, out nextFiftyLists);

// Set the Contact List for your
ContactOptInList optInList = new ContactOptInList();
optInList.ContactList = contactLists[0];
optInList.OptInSource = ContactOptSource.ActionByContact;

// Add this list to the Contacts subscription list
contact.ContactLists.Add(optInList);

// Create New Contact
contact = Utility.CreateNewContact(authdata, contact);

// Update Contact Information
contact.FirstName = "Joe";
contact.LastName = "Smith";
Utility.UpdateContactFullForm(authdata, contact);

// Move a Contact to Do Not Mail
Utility.UnsubscribeContact(authdata, contact.Id);
Dave Berard
Senior Product Manager, Constant Contact

The API works fine returning the contact, but not the list option associated with the contact.  However, I'm trying to read the correct ContactOptInList for a contact, but the API returns only the default  (ex General Intrest).  What is the correct method to return the contact's list options (so we can Identify what selection they made). Also, the correct method to meodify a contact's list option. 

If you're basing off this code snippet I provided, it will always add the Contact to only your General Interest list (if that is the first list).  You would probably need to modify which Contact Lists you are adding the Contact to to ensure that that they are added to the right lists.

 

If you are looking up an existing Contact that is a member of one or more lists, the API will return the full breakdown of all the lists they are members of.  If you're having a problem with that, please post the code you're using and PM me your username.  This way I can look at the actual data to see if we can find a problem.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page