I'm working with version 2 of the C# wrapper to add contacts. I also want to add them to an existing list at the same time. I've reviewed the samples and have a general idea of what needs to be done. The one part I'm unclear about is how to associate a new contact with an existing list. The only sample code I can find shows how to add a new list.
Below is what I'm working with:
Contact contact = null;
// Lookup each contact to determine if they exist in a list
ConstantContact cc = new ConstantContact();
contact = GetContactByEmailAddress(strEmail,cc);
if (contact == null)
{
// Build contact
contact.FirstName = dr["FIRST_NAME"].ToString();
contact.LastName = dr["LAST_NAME"].ToString();
contact.CompanyName = dr["NAME"].ToString();
contact.JobTitle = dr["TITLE"].ToString();
contact.WorkPhone = dr["PHONE_OFFICE"].ToString();
contact.EmailAddresses.Add(newEmailAddress() { EmailAddr = dr["EMAIL1"].ToString(),ConfirmStatus = Con firmStatus.NoConfirmationRequired, Status = Status.Active });
// How do I assign a contact to an existing list
contact.Lists.Add((new ContactList() { Id = "1", Status = Status.Active });
// ------------------------------------------------------------------------
// Add the contact to the Constant Contact item
Contact nc = cc.AddContact(contact, false);
};
Any assistance would be greatly appreciated. Thanks.
Hi,
It might look like a new list is getting created in the wrapper, when it's really just retrieving a list and associating it with a contact. You can see how the wrapper adds a list to a new contact around line 232 of the v2 .NET wrapper file found here.
contact.Lists.Add(newContactList(){Id="1",Status=Status.Active});
Best Regards,
Shannon W.
API Support Specialist
Thanks.
One more question I have is how do I get a list of the ids of each contact list. I've been looking around with no luck. I've found GetLists but uncertain if it is the right method.
The GetLists function will pull your account lists, but it wouldn't naturally print out the list of lists with their listID's like [I think] you want. Unless you need to pull the information dynamically, you can view the list ID's through the UI.
You would login to the account, go to the Contacts tab, click on a list, and look at the URL. It should look something like this:
https://ui.constantcontact.com/rnavmap/em/contacts/browse?listId=3&srchwithinlst=true
In this case, the list ID is 3. I hope that helps!
Best Regards,
Shannon W.
API Support Specialist
Thanks.