C# Wrapper Bulk Add/Update Contacts

Highlighted
Occasional Contributor

C# Wrapper Bulk Add/Update Contacts

Am I missing a method in the C# wrapper that can bulk add/update contacts but I'm not seeing anything in the wrapper for that. Does it exist?

 

My plan is to do a bulk add/update to do the initial put, then my understanding is I have to then loop through again to get the ID's since the bulk operation doesn't return them. Then on updates, recall them by ID and update them. Is this the correct way to go? This is all happening in a Windows service, not ASP.net.

 

Thanks,

 

13 REPLIES 13
Highlighted
CTCT Employee

Re: C# Wrapper Bulk Add/Update Contacts

Hi,

 

There is a bulk upload method in the wrapper.  You can find it in Utility.cs under bulkUrlEncoded (or do a search for "bulk"  in that file).

 

I wouldn't loop back through to get ID's once your contacts are added; I would do a search for contact by email address to find the ID of the contact you'd like to update and then update appropriately whenever you need to update a particular contact.  You are correct that we don't return the contact ID's for bulk actions through the API.

 

I don't have an example for the bulk upload, but to update an existing contact you could do something like below.  Let me know if you'd like my C# script that adds contacts individually or updates them if they already exist (new contacts are handled differently than existing contacts).  You should use the bulk upload method if you'd like to upload/update a large number of contacts at once.

 

//Contact update example
string _nextChunk;
string emailAddress = "test_01242013@test.com";
List<string> email = new List<string>();
email.Add(emailAddress);
IList<Contact> myContact = Utility.SearchContactByEmail(authdata, email, out _nextChunk);

//Get Contact by ID
Contact contact = Utility.GetContactDetailsById(authdata, myContact[0].Id);
contact.EmailAddress = emailAddress;

//Add Lists
ContactOptInList newList = new ContactOptInList();
newList.ContactList = new ContactList("1"); //Contact list you want to add them to
contact.ContactLists.Add(newList);
contact.OptInSource = ContactOptSource.ActionByContact; //set to ActionByCustomer if you'd like to suppress email notifications

//Add contact properties
contact.FirstName = "Joe";
contact.LastName = "Test";

//Update contact
Utility.UpdateContactFullForm(authdata, contact);

 

 

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: C# Wrapper Bulk Add/Update Contacts

Thanks Shannon,

 

So each time I want to update to contact I should recall them by their email, then make my changes, then post again using their ID? In that case do I even need to save their ID locally for anything?


And yes, I'd love to see any examples you have. Thank you.

Highlighted
CTCT Employee

Re: C# Wrapper Bulk Add/Update Contacts

Exactly right, I wouldn't store the ID's locally on your side, just query by email address to do the update.  Here is my script to add a contact if not already in the system, or update it if it is.  It is basically the functionality for a signup form (on a website), but it sounds like you want to do a bulk upload then just updates as needed.

 

/*
//Contact add/update example
string _nextChunk;
string emailAddress = "test_01242013@test.com";
List<string> email = new List<string>();
email.Add(emailAddress);
IList<Contact> myContact = Utility.SearchContactByEmail(authdata, email, out _nextChunk);
				
if (myContact.Count == 0)
{//Contact Does not exist, create new contact

	Contact contact = new Contact();
	contact.EmailAddress = emailAddress;
		
	//Add Lists
	ContactOptInList newList = new ContactOptInList();
	newList.ContactList = new ContactList("1"); //Contact list you want to add them to
	contact.ContactLists.Add(newList);

	//Add contact properties
	contact.FirstName = "Joe";
	contact.LastName = "Test";
	contact.OptInSource = ContactOptSource.ActionByContact;

	//Add contact
	Utility.CreateNewContact(authdata, contact);
}

else
{//Contact does exist,  update existing
	//Get Contact by ID
	Contact contact = Utility.GetContactDetailsById(authdata, myContact[0].Id);
	contact.EmailAddress = emailAddress;

	//Add Lists
	ContactOptInList newList = new ContactOptInList();
	newList.ContactList = new ContactList("1"); //Contact list you want to add them to
	contact.ContactLists.Add(newList);
	contact.OptInSource = ContactOptSource.ActionByContact;

	//Add contact properties
	contact.FirstName = "Joe";
	contact.LastName = "Test";
	   
	//Update contact
	Utility.UpdateContactFullForm(authdata, contact);
}

 

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: C# Wrapper Bulk Add/Update Contacts

Thanks again, Shannon. That was pretty much how I envisioned it.

 

What is the recommended approach for bulk updates? If there are more than x posts to perform then use bulk, otherwise use invidivual? What would X be? Or should it just be if there are more than 1 insert/update to perform, use bulk?

Highlighted
CTCT Employee

Re: C# Wrapper Bulk Add/Update Contacts

Hi,

 

I would recommend using the bulk uploader for anything more than 1 contact.  By the time you get to updating more than 5 contacts at a time individually, you can start to see a script fail.

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: C# Wrapper Bulk Add/Update Contacts

Thanks for the fast replies, Shannon. Appreciate it! I'll let you know how it goes!

Highlighted
Occasional Contributor

Re: C# Wrapper Bulk Add/Update Contacts

bulkUrlEncoded is a mess in my opinion. You should write a new method in your wrapper that allows you to take an ILIst<Contact> and deal with all of these field mappings for you.

Highlighted
Occasional Contributor

Re: C# Wrapper Bulk Add/Update Contacts

Also, if I'm just going to be using bulk post for every call, do I even need to search for contacts by email first? Or will the bulk do updates/inserts where appropriate without me needing to worry about it?

Highlighted
Visitor

Re: C# Wrapper Bulk Add/Update Contacts

One more, can I set do not mail from bulk?

 

Say I go through and add everyone to list, then in my system they're removed from mailing list, I want to remove them from CC. How can I do that with bulkUrlEncoded?

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