500 Error when trying to bulk add

Participant

500 Error when trying to bulk add

Hello,

 

I am attempting to bulk add a bunch of contacts using the Bulk Activities API, but ran into a 500 error. I am using the httplib2 library for python to construct my requests. Here is the code sample that caused the error:

h = httplib2.Http(disable_ssl_certificate_validation=True)
uri = 'https://api.constantcontact.com/ws/customers/captricity/activities'
method = 'POST'
body = 'activityType=SV_ADD&data=Email+Address%2CFirst+Name%2CLast+Name%0Awstest3%40example.com%2C+Fred%2C+Test%0Awstest4%40example.com%2C+Joan%2C+Test%0Awstest5%40example.com%2C+Ann%2C+Test'
headers = {'contenttype': 'application/x-www-form-urlencoded', 'accept-encoding': 'gzip, deflate', 'authorization': u'<OAUTH2 TOKEN>', 'user-agent': 'captricity'}
h.request(uri, method, body, headers)

Does something look amiss here?

 

Thanks

2 REPLIES 2
Moderator

Definitely a few problems here, some of which could cause 500 errors and some would cause 400 errors if the request got through.

 

First off, the header you're setting for Content-Type is incorrect, that header requires a hyphen in it per the HTTP spec.  You'll want to update that so that you are sending us a content-type header. 

 

I'm not overly familiar with python, so I'm not sure if you are setting the authorization correctly.  For OAuth 2.0, the format should be:

 

header name: authorization

header value: 'bearer {Access_token}'

 

I don't know what the u'' means for a string in python, but I wanted to make sure you were setting the header value to have the word bearer in the value or it will not work. 

 

The last piece which will cause 400 errors when the request is submitted would be the lack of a list parameter in the query parameter list.  Without a proper list for us to add the Contacts to, this request will fail to go through.  You must specificy at least one list parameter, see our documentation here: http://community.constantcontact.com/t5/Documentation/Creating-an-Add-Contacts-Remove-Contacts-Activ...

Dave Berard
Senior Product Manager, Constant Contact

Dave,

 

Oh silly me. I'm embarassed to have asked that question: I didn't realize I had missed the hyphen in the header.

 

As for the other two points, the Oauth header is set correctly, with the bearer and token. I knew this was not the primary error as it is automatically set by httplib2 using the credentials feature, but thanks for the clarification. For your knowledge, the u'' syntax for python marks a string as unicode. Also thanks for clarifying that a list was necessary as I would have fumbled some more trying to figure that out.

 

Thanks for your help!

Developer Portal

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

Visit Page