cancel
Showing results for 
Search instead for 
Did you mean: 

500 Error on Contact Update

All Star

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"/>
  <id>http://api.constantcontact.com/ws/customers/{my-username}/contacts/3372</id>
  <title type="text">Contact: chris@sinchok.com</title>
  <updated>2011-07-05T01:56:38.738Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <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/">
      <Status>Active</Status>
      <EmailAddress>chris@sinchok.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name>Chris Sinchok</Name>
      <FirstName>Chris</FirstName>
      <MiddleName/>
      <LastName>Sinchok</LastName>
      <JobTitle/>
      <CompanyName/>
      <HomePhone/>
      <WorkPhone/>
      <Addr1/>
      <Addr2/>
      <Addr3/>
      <City/>
      <StateCode/>
      <StateName/>
      <CountryCode/>
      <CountryName/>
      <PostalCode/>
      <SubPostalCode/>
      <Note/>
      <CustomField1>7e2b8117ba8c33c7a117365fe2a1020047a22a749492f080742c1c2c</CustomField1>
      <CustomField2/>
      <CustomField3/>
      <CustomField4/>
      <CustomField5/>
      <CustomField6/>
      <CustomField7/>
      <CustomField8>575.0</CustomField8>
      <CustomField9>2011 SMALL CSA spot holder</CustomField9>
      <CustomField10>2011 SMALL CSA spot holder</CustomField10>
      <CustomField11>Full Upfront</CustomField11>
      <CustomField12>Beachwood</CustomField12>
      <CustomField13>575.0</CustomField13>
      <CustomField14>195.0</CustomField14>
      <CustomField15>380.0</CustomField15>
      <ContactLists>
...{lists trimmed for brevity}...
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-05-04T13:04:10.551Z</InsertTime>
      <LastUpdateTime>2011-07-05T01:56:38.738Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/{my-username}/contacts</id>
    <title type="text">Contacts for Customer: {my-username}</title>
    <link href="contacts"/>
    <link href="contacts" rel="self"/>
    <author>
      <name>{my-username}</name>
    </author>
    <updated>2011-07-05T01:56:38.738Z</updated>
  </source>
</entry>

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

3 REPLIES 3
CTCT Employee

Re: 500 Error on Contact Update

Hello,

 

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.

 

Sincerely,

Benjamin Soder
NOC Analyst
Constant Contact
All Star

Re: 500 Error on Contact Update

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)

 

Highlighted
CTCT Employee

Re: 500 Error on Contact Update

Hello,

 

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?

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact