Updating a Contact
To update a contact's information, the best way is to get details of an existing contact, modify the details, and use the resulting XML in a PUT method. You will use the following URI to GET and PUT the contact.
https://api.constantcontact.com/ws/customers/{username}/contacts/{contact-id}
The request body you use for a PUT must contain all elements that belong to a contact, which are returned through the GET method. By using this XML, you should modify only the information you would like to update, then pass the XML in your request.
To modify the contact's subscriptions to different contact lists, you need to update contents of <ContactLists> element. You must include all of the contact lists that the contact should be on. Therefore, you should add the new list subscriptions to the existing lists in the XML returned by the GET.
Opting in a Contact Who Was Unsubscribed
Contacts who have opted out of receiving all mails and have been placed on Do-Not-Mail list must opt themselves in. The account owner cannot add a contact in Do-Not-Mail list back to a different list. The action must be initiated by the contact. When using the API, that means that the <OptInSource
> must be ACTION_BY_CONTACT
, which can only be used when the API call is the direct result of an action performed by the contact (e.g. clicking a Subscribe button in an application). It is a serious violation of the Constant Contact Terms of Service to use the Opt-in features of the API in any other way (i.e. opting in a contact without his or her action and consent).
In order to opt-in a contact, you must take the contact's detail data and modify <ContactLists> to include the contact contact lists in which the contact is signing up. You also need to add an OptInSource node at the contact level with a value of ACTION_BY_CONTACT. Then, you use the PUT method to apply the change against the contact resource:
https://api.constantcontact.com/ws/customers/{username}/contacts/{contact-id}
Below is the format of the XML to opt-in a contact. It adds the OptInSource node at the Contact level (as opposed to only being at the List level in a GET).
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/joesflowers/contacts/2249" rel="edit" />
<id>http://api.constantcontact.com/ws/customers/joesflowers/contacts/2249</id>
<title type="text">Contact: joe@example.com</title>
<updated>2009-11-20T20:41:19.243Z</updated>
<author>
<name>Constant Contact</name>
</author>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/2249">
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<Status>Active</Status>
<EmailAddress>joe@example.com</EmailAddress>
<EmailType>HTML</EmailType>
<Name>Customer Joe</Name>
<FirstName>Joe</FirstName>
<MiddleName></MiddleName>
<LastName>Smith</LastName>
<JobTitle></JobTitle>
<CompanyName></CompanyName>
<HomePhone></HomePhone>
<WorkPhone></WorkPhone>
<Addr1></Addr1>
<Addr2></Addr2>
<Addr3></Addr3>
<City></City>
<StateCode>MA</StateCode>
<StateName>Massachusetts</StateName>
<CountryCode>us</CountryCode>
<CountryName>United States</CountryName>
<PostalCode>02154</PostalCode>
<SubPostalCode>1781</SubPostalCode>
<Note></Note>
<CustomField1></CustomField1>
<CustomField2></CustomField2>
<CustomField3></CustomField3>
<CustomField4></CustomField4>
<CustomField5></CustomField5>
<CustomField6></CustomField6>
<CustomField7></CustomField7>
<CustomField8></CustomField8>
<CustomField9></CustomField9>
<CustomField10></CustomField10>
<CustomField11></CustomField11>
<CustomField12></CustomField12>
<CustomField13></CustomField13>
<CustomField14></CustomField14>
<CustomField15></CustomField15>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/1">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/joesflowers/lists/1" rel="self" />
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<OptInTime>2009-11-20T20:41:06.595Z</OptInTime>
</ContactList>
</ContactLists>
<Confirmed>true</Confirmed>
<InsertTime>2009-11-20T20:41:06.593Z</InsertTime>
<LastUpdateTime>2009-11-20T20:41:19.243Z</LastUpdateTime>
</Contact>
</content>
<source>
<id>http://api.constantcontact.com/ws/customers/joesflowers/contacts</id>
<title type="text">Contacts for Customer: joesflowers</title>
<link href="contacts" />
<link href="contacts" rel="self" />
<author>
<name>joesflowers</name>
</author>
<updated>2009-11-20T20:45:44.199Z</updated>
</source>
</entry>