409 Error

Regular Participant

409 Error

Hi,


I'm trying to implement constant contact API using php. My code was working for a month, but now it has stopped working. File hasn't been updated for a month now. I get this error "The requested URL returned error: 409" when someone tries to sign up. 


Would be alright to post my code here?


 

14 REPLIES 14
Employee

You can certainly post your code here if you're comfortable with that, otherwise you can feel free to send an email to our webservices support team and we would be happy to take a look there instead.


Regarding the 409 error you are receiving, this is typically due to a conflict in the resource you are trying to post. For example attempting to create a contact that already exists in your system would return a 409. You can verify if this contact exists already or not by Searching for Contact by Email Address. You can also find a list of all of our error codes at http://developer.constantcontact.com/doc/errorCodes.


I hope this helps. Please let us know if you have any other questions or concerns. Thanks.

David J

Is there anywhere that I can find a list of all possible errors that could be returned when trying to add a user via PHP API ($ConstantContact->addContact)? I need to do error checking on a website I am builiding and can't find these codes anywere. I know that there is a 401 and 409 errors, but what else? 

 

http://developer.constantcontact.com/doc/errorCodes does not have such a listing.

Hello,

 

You can find a general list of HTTP status codes that will be returned by the API here: http://community.constantcontact.com/t5/Documentation/Error-Codes/ba-p/25077

 

As far as the HTTP status codes that could be returned while adding a user:

 

201 - Created (Success) - A new contact was created
204 - Updated (Success) - A contact was updated
400 - Invalid Request - The request format was invalid. Usually indicates an XML error.
401 - Unauthorized - The request failed to authenticate. Double-check your credentials before trying again.
409 - Conflict - A contact already exists and you need to update the contact instead of adding a new contact. (PUT instead of POST)

 

If you have any furhter questions, please reply to this post and we will be happy to assist you!

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API Support Engineer
Regular Participant

 include_once('cc_class.php');


$ccContactOBJ = new CC_Contact();


$ccListOBJ = new CC_List(); 


/**


 * If we have post fields means that the form have been submitted.


 * Therefore we start submiting inserted data to ConstantContact Server. 


 */


if (!empty($_POST)) {


 


//Adding an array to store contact list(s) the user should be subscribed to 'babylon'; 


$lists = array();


$lists[] = "http://api.constantcontact.com/ws/customers/onerace/lists/1";




$postFields = array();


$postFields = $_POST;



//Assign the array of lists to the postFields lists array


$postFields = $lists;




foreach($_POST as $key=>$val) {



if (strncmp($key, 'custom_field_', strlen('custom_field_')) === 0) {


$postFields = $val;


}


 


}


 


$contactXML = $ccContactOBJ->createContactXML(null,$postFields);



if (!$ccContactOBJ->addSubscriber($contactXML)) {


$error = true;


} else {


$error = false;


$_POST = array();


}


 


}



if (isset($error)) {



if ($error === true) {


$message = $ccContactOBJ->lastError;


//echo "success=no";


} else {


                //echo "success=yes";


                header("Location: redirectpage.php");


}      


}

Regular Participant

 I searched the database and email address I'm trying to add does not exist.

Employee

A 409 error should not be happening if that contact does not exist. In order to really dig into this, I would need to have your username, as well as the email address that you are looking to add to your account. If you can either reply to this with that information, or email it to out webservices support team, I'd be happy to look into this.

David J

Regular Participant

I'm having the same error (The requested URL returned error: 409).

Regular Participant

This is my XML

 

<entry xmlns="http://www.w3.org/2005/Atom"><title>TitleNode</title><updated>2011-08-02T11:16:37+01:00</updated><author><name>CTCT Samples</name></author><id>urn:uuid:E8553C09F4xcvxCCC53F481214230867087</id><summary type="text">Customer document</summary><content type="application/vnd.ctct+xml"><Contact xmlns="http://ws.constantcontact.com/ns/1.0/">Customer document<EmailAddress>sgrowing@gmail.com</EmailAddress><FirstName></FirstName><LastName></LastName><MiddleName></MiddleName><CompanyName></CompanyName><JobTitle></JobTitle><OptInSource>ACTION_BY_CONTACT</OptInSource><HomePhone></HomePhone><WorkPhone></WorkPhone><Addr1></Addr1><Addr2></Addr2><Addr3></Addr3><City></City><StateCode></StateCode><StateName></StateName><CountryCode></CountryCode><PostalCode></PostalCode><SubPostalCode></SubPostalCode><Note></Note><EmailType></EmailType><ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/orbitDev/lists/1"/><ContactList id="http://api.constantcontact.com/ws/customers/orbitDev/lists/2"/></ContactLists></Contact></content></entry>

Regular Participant

Sorry for the rapid-fire posts...a small update:

 

I've found that I am receiving this error when trying to sign up with an email that is currently on my list or has been previously added. For example, I added my email address, and was successful. I logged into constant contact and removed my email address from all lists. When I tried to add my email address again, I got the error. To test, I tried this several different times with different addresses...it looks like I can only sign up once with an email address...if I try to submit a duplicate OR I delete the email address and try to re-submit, I get an error 409.

 

Please help!

Hi Sam,

 

Whenever you remove a contact, they are put on the Removed List. In order to make them active again, you must update the contact instead of recreating it. See this page for more information.

 

Regards,

Richard Maxwell
Support Engineer, Constant Contact
Regular Participant

How would you do that using the PHP API?

 

I tried to use searchContactsByEmail() before doing the add but searchContactsByEmail() does not return the contact if they were on the removed list.

 

And so addContact() fails when you attempt to add an already removed contact.

 

Any help would be appreciated.

Hi,

 

Sorry for the delay in responding.  The API returns the contact details for a contact no matter what their status is (active, removed, or do not mail), and the wrapper doesn't differentiate between those statuses for searching purposes.  You should be able to search for a contact, get the contact object, and update it with the new status (active), add lists, and then update the contact object.

 

I hope that helps!

 

Best Regards,

Shannon W.

API Support Specialist

Regular Participant

I found the issue and it's to do with your PHP API.

 

I was doing the above testing using a Gmail account of the form "firstname.lastname+some_spam_label@gmail.com"

 

Gmail allows you to add "+whatever_you_like" to the email address and still route it properly to aid in testing of apps and so on.

 

It seems that the Constant Contact PHP API is not URL encoding the "+" in the email address correctly and so when it runs the search it does not find the email in question.

 

I can confirm this using the HTTP API from a web browser.

 

The following fails:

https://api.constantcontact.com/ws/customers/directsms/contacts?email=firstname.lastname+cc@gmail.co...

 

This works:

https://api.constantcontact.com/ws/customers/directsms/contacts?email=firstname.lastname%2Bcc@gmail....

 

We are very sorry for any inconvenience this has caused you.  We do thank you for reporting this to us.  We'll look into getting the wrapper updated to encode the email address.  

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Developer Portal

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

Visit Page