Activities Collection (BULK OPERATIONS) Problem if any Contact Field Value contains ","

Occasional Participant

Activities Collection (BULK OPERATIONS) Problem if any Contact Field Value contains ","

Hi,
I am trying to upload contacts to constant contact server using Bulk-Operation (using C#.NET).

I am using the following format provided at Constant Contact Developer site.

StringBuilder content = new StringBuilder();
content.Append("&data=");
content.Append(HttpUtility.UrlEncode("Email Address,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("First Name,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("Last Name", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("\n", Encoding.UTF8));

content.Append(HttpUtility.UrlEncode("shahid.saim@techno-soft.com,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("First Name,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("Last Name", Encoding.UTF8));

content.Append("&lists=");
content.Append(HttpUtility.UrlEncode("http://api.constantcontact.com/ws/customers/techno-soft/lists/1", Encoding.UTF8));

if i use the above code then it will upload
Email Address = shahid.saim@techno-soft.com
First Name = First Name
Last Name = Last Name
it is fine.


But the problem is, if i have "," character in any field value like,

StringBuilder content = new StringBuilder();
content.Append("&data=");
content.Append(HttpUtility.UrlEncode("Email Address,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("First Name,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("Last Name", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("\n", Encoding.UTF8));

content.Append(HttpUtility.UrlEncode("shahid.saim@techno-soft.com,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("First, Name,", Encoding.UTF8));
content.Append(HttpUtility.UrlEncode("Last Name", Encoding.UTF8));

content.Append("&lists=");
content.Append(HttpUtility.UrlEncode("http://api.constantcontact.com/ws/customers/techno-soft/lists/1", Encoding.UTF8));

then it will upload
Email Address = shahid.saim@techno-soft.com
First Name = First
Last Name = Name

If there is any "," in field value. then it will consider the next column. So, it will disturb the whole mapping of columns.
if anyone have idea, how can i handle this "," character then help me.
1 REPLY 1
Moderator

If I understand correctly, some of your data has a , in the information (i.e. "smith, john" for the First Name). If this is the case, the only resolution would be to replace the , with some other delimiter using some sort of parser prior to constructing the URIs. Since the , is our delimiting character for the data stream, it will treat this as a new data field and cause the behavior you are seeing. This will be easy since you are using C# strings. Simply use the following string function to replace the comma's in all your strings with some other symbol:

String FirstName = "Smith, John";
FirstName.Replace(",",";");


This will replace all commas in the FirstName string with a semi-colon. You can pick any character you want that is not a reserved character for creating a valid URI as the delimiter.

There is no way to get around the comma being treated as a delimiter using the Bulk Activity API, just as there is no way to get around it when using Comma Delimited Text files. The only alternative I can suggest is to use the Contacts Collection API instead. It will require you to create a valid XML document, but you can use any symbols you want in the XML document.
Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page