CT PHP Error

Regular Participant

CT PHP Error

This is the error I get


string(795) " http://api.constantcontact.com/ws/customers/username/contacts 2012-12-03T19:36:12.622Z/updated> {email} ACTION_BY_CUSTOMER " Fault Name: HttpRequestReceiveError Error Type: Default Description: Http request received failed Root Cause Code: -19015 Root Cause : HTTP Transport: Syntax error while parsing Binding State: CLIENT_CONNECTION_ESTABLISHED Service: null Endpoint: null Operation (Client): httpcode error is 400False


I do have the username and email place.


Does the email have to be associated with the Constant Contact Account.


Any help is appreciated. Thanks




Could I see the code you're using, or the payload you're sending us and the URI you're hitting, when you get that error?  Please keep obscuring your username and other sensitive details as applicable in your code.


Best Regards,

Shannon W.

API Support Specialist



Here is the code. Its a Drupal Site. I have a simple php form with just an email field for newletter subsription and woud like to automatically add this email to a particular list on Constant Contact.


Once the user hit's submit  - I have the following -


I spent a lot of time trying to get it to work and then I am trying to test in on the restclient.


$UN = 'username';
$PW = 'password';
$Key  = 'key';

$userNamePassword = $Key . '%' . $UN . ':' . $PW ;

$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text">Contact: tbeerapu@test.com</title>
<author> </author>
<content type="application/vnd.ctct+xml">
<Contact xmlns=" http://ws.constantcontact.com/ns/1.0/" id=" https://api.constantcontact.com/ws/customers/username/contacts">
<EmailAddress>$email</EmailAddress> // This will come for the form
<ContactList id="https://api.constantcontact.com/ws/customers/username/lists/8" />


       // Initialize the curl session
       $request ="https://api.constantcontact.com/ws/customers/username/contacts";

$session = curl_init($request);

curl_setopt($session, CURLOPT_USERPWD, $userNamePassword );
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//curl_setopt($session, CURLOPT_INFILE, $tmpfile);

curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $entry);
//curl_setopt($session, CURLOPT_INFILESIZE, strlen($entry));
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, false);   // Do not return headers

curl_setopt($session, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($session);
$httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);

Your XML looks correct, provided that list 8 is a valid list in your account.  The full error message would be returned to your $response variable if you change this line:


curl_setopt($session, CURLOPT_RETURNTRANSFER, 0);




curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);


Our full error message will be returned after the request is made for you to get the description back. 


There was one issue that I did see, though I am assuming this is a copy/paste issue.  There are spaces in your strings for the <Contact> node attributes, specifically xmlns and id.  These spaces caused a 500 error for me when I tried running your XML so it doesn't sound like that's what you're seeing, but I thought I'd mention it just to be safe.  If you can run your code and then provide the full error message that you're receiving, that would help to get you an answer as to what the problem is.

Dave Berard
Senior Product Manager, Constant Contact

Thank You for all the information. I used the php Library


I finally got it to work and the issue I was having were -


  1. OAuth - Username not found in datastore
  2. List ID not found


  1. Changed the Authorization to basic
  2. I just had the list ID, for example "x" in my array but instead it should be - http://api.constantcontact.com/ws/customers/info@cfsinnovation.com/lists/x

Great to hear, here's some feedback on the issues you ran into:


1. OAuth Username error - you need to have stored the OAuth 2 token and username in Session (we implemented a simple datastore class that you can use to load/store this if you don't want to hard code that) in order to use OAuth.  I know you worked around this with Basic but we have depricated Basic authentication.  While we do not have immediate plans to turn it off, we do have it as a long term goal to completely end all access to the API through Basic. 

2. List ID - this is a documentation/usability issue we're looking at a way to resolve.  Would love to hear your feedback as to both how you expected it to behave and how you would have liked to seen this documented.  In the next version of our API, we're also simplifying ID values completely to only be a number and not a URI.  We've found the URI required by ATOM XML format to be very confusing to our developers and not overly useful.

Dave Berard
Senior Product Manager, Constant Contact

Good to know that.


Will you be sending any notifications to user that you will be removing the "basic". Can you send some links with info on setting the session variables?


And as far as the List ID is concerned, just like you said I was hoping we can just enter the ID and not the URI because anyways the ID itself is the uniquie parameter.



Our PHP Wrapper Library includes an example verification flow (example_verfication.php in the root folder of the library), and an additional standalone example can be found in the Authentication page of the Wiki for the PHP library.

The Datastore class implemented in these authentication flow stores the necessary credentials in the $_SESSION array, so it's useful as long as the user's connection with our server is maintained.


Because the $_SESSION array is lost if the session isn't maintained, if you need to eliminate the need to re-authorize with each new session, we encourage you add the necessary functions to your local copy of the Datastore class, or you may include your own class to pull the authentication data from the $_SESSION after users authorize, and set a cookie in the client browser, or store it securely in a SQL database table, for example. 


The specifics of how you do this depend on the nature of your application. An application hosted on your own server but used by many may work best using a client flow for oAuth 2 and cookies on the client side , while installation of your application on each user's webhost would probably work best with server/web application flow oAuth 2 (implemented in the oAuth 2 examples mentioend above), and server-side storage of the access token. For technical details of our oAuth 2 server and client flow implementation, see our oAuth 2 Authentication Documentation.


I hope this information is helpful to you.  Let us know if you have additional questions.

Mark Coleman
Support Engineer
Developer Portal

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

Visit Page