500 Error on Contact Update


500 Error on Contact Update

I'm having an issue updating contact information via the API. Essentially, I'm using a GET request to retrieve the contact XML, making the necessary updates, and the PUT'ing it back, but am getting a 500 on the PUT request. I've checked the XML, and everything looks fine to me, but there still may be some error there. I've tested the PUT  in my code, and also using the "Poster" Firefox extension. I'm posting to the URL: https://api.constantcontact.com/ws/customers/{my-username}/contacts/3372


This is the XMl data:


<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/{my-username}/contacts/3372" rel="edit"/>
  <title type="text">Contact: chris@sinchok.com</title>
    <name>Constant Contact</name>
  <content type="application/vnd.ctct+xml">
    <Contact id="http://api.constantcontact.com/ws/customers/{my-username}/contacts/3372" xmlns="http://ws.constantcontact.com/ns/1.0/">
      <Name>Chris Sinchok</Name>
      <CustomField9>2011 SMALL CSA spot holder</CustomField9>
      <CustomField10>2011 SMALL CSA spot holder</CustomField10>
      <CustomField11>Full Upfront</CustomField11>
...{lists trimmed for brevity}...
    <title type="text">Contacts for Customer: {my-username}</title>
    <link href="contacts"/>
    <link href="contacts" rel="self"/>

I'd appriciate any ideas on how to resolve this issue.




I took a look at your XML and I was able to PUT it successfully into my account with one change.  It appears that you are not sending it with UTF-8 encoding.  Our system does require this to be specified:


<?xml version="1.0" encoding="UTF-8"?>


Once you have changed this, it should work fine.


If you have any questions please let me know.



Benjamin Soder
NOC Analyst
Constant Contact

I tried to PUT the exact XML above (with an acctual username inserted), but with the UTF-8 encoding parameter, and am still getting a 500. Not sure if this will help, but here is the actual Python code that I'm using:


import urllib2
import datetime
from xml.dom import minidom

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
top_level_url = "https://api.constantcontact.com/ws/customers/{my-username}/"
password_mgr.add_password(None, top_level_url, 'USER_NAME_STRING', 'PASSWORD')
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)

request_string = 'https://api.constantcontact.com/ws/customers/{my-username}/contacts/%s' % constant_contact_id
response = self.opener.open(request_string)
xml_string = response.read()
dom = minidom.parseString(xml_string)

dom.getElementsByTagName('CustomField1')[0].childNodes[0].nodeValue = "Some test value"
dom.getElementsByTagName('CustomField15')[0].childNodes[0].nodeValue = "Some other test value"

update_request = urllib2.Request(request_string, data=dom.toxml(encoding="UTF-8"))
update_request.add_header('Content-Type', 'application/atom+xml')
update_request.get_method = lambda: 'PUT'

print('Putting to: %s' % update_request.get_full_url())
print("Data: %s" % update_request.get_data())

update_response = self.opener.open(update_request)




The XML is definitely correct.  I substituted just the usernames out and it is definitely successfully updating on my end.  I am not 100% familiar with python, but can you send me the entire file, and I can take a look at it further?



Benjamin Soder
NOC Analyst
Constant Contact
Developer Portal

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

Visit Page