The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Unable to update custom fields through API

Highlighted
New Member

Unable to update custom fields through API

 Hello,


I'm using the CTCTWSJavaLib Java library to update contact information using the API. I have no problem updating standard fields, such as "CompanyName" and "Addr1", but my updates to custom fields, such as "CustomField7" or "CustomField10", are not being saved. In my case, "CustomField7" (but not "CustomField10") has been renamed through the Join My Mailing List screens, but the updates don't work through the API using both the original name ("CustomField7") or the new name. I'm wondering what is it that I'm doing wrong, as custom fields are listed as editable on the API documentation (http://developer.constantcontact.com/doc/contactCollection).


I would appreciate any help with this.


 

2 REPLIES 2
Highlighted
New Member

I found a solution for this.

I found a solution for this. I downloaded the source code for the CTCTWSJavaLib and inspected it. The javadoc for the Contact class does mention the fields that are retrieved and updated, and custom fields are not considered; that's why they are not updated with my request. However, it's easy to modify the source code to include the custom fields. In case anyone is interested, here's what I did (keep in mind that this may not be the optimal solution):


On Contact.java, on the generateAttributesXmlRequest() method, I added the following lines between the lines that append the "Notes" attribute and those that append the "ContactLists" element:


 


 


String customFieldName = "";


for (int i = 1; i <= 15; i++) {


customFieldName = "CustomField" + i;


if(hasAttribute(customFieldName)) {


builder.append("<" + customFieldName + ">");


builder.append(attributes.get(customFieldName));


builder.append("</" + customFieldName + ">");


}


}


 


 


 This takes care of sending the values of the custom fields (1 to 15) in the request. To retrieve the values of the custom fields from the response, I added the following lines to the end of the if block of the endElement() method of the same class, that is, Contact (if you take a look at the source code, it's immediately evident where these lines should be placed):


 


else if(qName.startsWith("CustomField")) {


attributes.put(qName, currentString);


}


This takes care of retreiving the values of the 15 custom fields. 


Let me know what you all think (there may be a better solution).


 

Highlighted
Moderator

Thanks for the update.  The

Thanks for the update.  The Java code you are talking about I believe is an open source library.  Have you considered contributing and updating the code to reflect this for future users?  Any help contributing to the open source community is greatly appreciated.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured