Error while Updating contact Email through API

Occasional Participant

Error while Updating contact Email through API

Hi, I am implementing API in php. I have created a form which allow user to update there contact information. After form POST i am collecting records related to email and then updating that xml with request method as PUT. The problem is that sometimes its update contact email plus other details successfully but sometime it creates a new contact, instead of updating . I have searched a lot on API and forum but did not found anything related.


i have attached the XML i am using for update:


Please help.

6 REPLIES 6
Employee

The XML used for a POST and PUT in regards to creating a contact can be the exact same, and the differences between a POST and PUT can be as small as the HTTP method and the URL being submitted to. A new contact should never be created however if you are using the HTTP put method, as this will only update, and a post should only be creating a new contact.


It sounds like there may be some logic in your program to determine whether a contact exists or not. If the contact exists, it performs a put to the link for that contact (ie: https://api.constantcontact.com/ws/customers/{user-name}/contacts/{contact-id}), if not, it would perform a post to the contacts collection (https://api.constantcontact.com/ws/customers/{user-name}/contacts).


If you would like to send your PHP code to our webservices support team, I would be happy to take a look and see if I can assist in troubleshooting this.

David J

Occasional Participant

 this is the request url i am using:

https://api.constantcontact.com/ws/customers/pushap/contacts/63


Method: PUT


Return code: 204


i have  Attached XML in use in earlier post.

 


if i echo o/p after request then it looks some thing like this:

https://api.constantcontact.com/ws/customers/pushap/contacts/63 <<>>



http://api.constantcontact.com/ws/customers/pushap/contacts/63 2010-08-11T09:41:52+01:00 Constant Contact Active f4444444f2w1w1w1@sada.com HTML rr rr sdsad asds asd
asdsa asdasd
ACTION_BY_CONTACT 2010-08-11T00:45:00.374Z

ACTION_BY_CONTACT 2010-08-11T13:08:18.456Z

ACTION_BY_CONTACT 2010-08-11T14:26:59.160Z

ACTION_BY_CONTACT 2010-08-11T14:25:57.452Z

ACTION_BY_CONTACT 2010-08-11T13:07:40.437Z
false 2010-08-11T00:45:00.366Z 2010-08-11T14:36:32.652Z ACTION_BY_CONTACT
http://api.constantcontact.com/ws/customers/pushap/contacts

pushap 2010-08-11T16:41:52.450Z
<<>>



PUT <<>>



204


I checked the result of check i applied for email existance and it always return me the responce object if contact exists.  Do i need to pass old email id in xml or only the new one which is being updated by user.

Employee

Hello,



When doing a PUT to update a contact, the Contacts ID would never change, so you can pass the new email address, or any new information, to the URI with the Contact ID, such as what you had given as an example. This will change the email address of the contact, but the Contact ID will never change.



Whenever you do a PUT call, there is no functionality built in that would create a contact. The only way a new contact ID would be created is if you were doing a POST call.



If you are still having an issue with the code creating contacts when it should be updating, please feel free to send us your code, to the webservices support team.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Regular Participant

I am having a similar problem...

Every time I try to do an update, it returns a 409 error.

I took the example from your page:

http://developer.constantcontact.com/doc/manageSubscriptions:


Here is the xml


 



<entry xmlns="http://www.w3.org/2005/Atom">
<id>https://api.constantcontact.com/ws/customers/mylogin/contacts/22222</id>
<title type="text">Contact: joe@gmail.com</title>


<updated>2010-08-11T15:24:33+01:00</updated>
<author></author>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="https://api.constantcontact.com/ws/customers/mylogin/contacts/22222">
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<EmailAddress>joe@gmail.com</EmailAddress>
<ContactLists>


<ContactList id="https://api.constantcontact.com/ws/customers/mylogin/lists/123"></ContactList>
<ContactList id="https://api.constantcontact.com/ws/customers/mylogin/lists/456"></ContactList>
</ContactLists>
</Contact>
</content>
</entry>U

Email and Ids changed for privacy.


 


I used almost identical to create the user and all went well.

I verified that the curl method is PUT, but still NO JOY...


Any Ideas?

Employee

Hi



When you receive a 409 error it normally means that the XML you are using is not correct in some way. I noticed that you stated you were taking the create contact XML to do the PUT.



The reason this way is usually not advisable is because when doing a PUT call, the XML needs to be exactly the same as the current XML that is already assigned to that contact, except for the changes that are being made.



The best way to ensure that this is happening, is to do a GET call on the specific contact, and take the XML and modify it, and then return the XML to us with a PUT call. This will make sure that the XML is correct.



You can read more about this here.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Regular Participant

I reworked all of my code to use your cc_class.php methods for manipulating the Contact Data XML.


That seems to have fixed the issues.


Still there was a bunch of trial and error to determine what succeeded and failed, but its working now.


Thanks for your assistance on this.

Developer Portal

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

Visit Page