Hello josephineo,
Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.
When Updating an existing contact using PUT /Contacts, we need to append the new information to the old information and send all of it back in the request, because when you update a contact using a PUT, all properties are updated, overwriting all existing property values. Any properties left blank or not included in the PUT will be overwritten with a null value.
Here's the flow you'll want to use to ensure that data is not overwritten for existing contacts:
First, check to see if the contact exists in the account using the email query parameter to search for a contact using a specific email address.
For the GET /contacts call, this is how we'll want to format the request URL to make sure we're checking for deleted or unsubscribed contacts, rather than just active ones, and ensure that we are retrieving all of the existing contact data to send back with the new contact data
GET
https://api.cc.email/v3/contacts?email=dlang@example.com&status=all&include=custom_fields,list_memberships,phone_numbers,street_addresses,taggings,notes
{
"contact_id": "1618ae62-4752-11e9-9c8a-fa163e6b01c1",
"email_address": {
"address": "dlang@example.com",
"permission_to_send": "implicit",
"created_at": "2016-03-03T15:53:04.000+00:00",
"updated_at": "2016-03-03T15:56:29.000+00:00",
"opt_in_source": "Contact",
"opt_in_date": "2016-01-23T13:48:44.108Z",
"confirm_status": "confirmed"
},
"first_name": "Debora",
"last_name": "Lang",
"update_source": "Contact",
"create_source": "Account",
"created_at": "2016-01-23T13:48:44.108Z",
"updated_at": "2016-01-23T13:48:44.108Z",
"deleted_at": "2016-07-08",
"custom_fields": [
{
"custom_field_id": "1618ae62-4752-11e9-9c8a-fa163e6b01c1",
"value": "Existing Custom Field Value"
}
],
[ … ]
You need to append the returned data with the new data and send all of it back with PUT to update the contact.
So, from that response body, the "contact_id" is going to go in our PUT /contacts URL, and then you'll take the rest of the data from the response to build your request body like so:
PUT
https://api.cc.email/v3/contacts/1618ae62-4752-11e9-9c8a-fa163e6b01c1
{
"email_address": {
"address": "dlang@example.com",
"permission_to_send": "implicit",
"created_at": "2016-03-03T15:53:04.000+00:00",
"updated_at": "2016-03-03T15:56:29.000+00:00",
"opt_in_date": "2016-01-23T13:48:44.108Z",
"confirm_status": "confirmed"
},
"first_name": "Debora",
"last_name": "Lang",
"update_source": "Account",
"custom_fields": [
{
"custom_field_id": "1618ae62-4752-11e9-9c8a-fa163e6b01c1",
"value": "Existing Custom Field Value"
},
{
"custom_field_id": "f1a83568-b41c-11eb-839c-fa163ed93e4f",
"value": "New Custom Field value 1"
},
{
"custom_field_id": "f1a83568-b41c-11eb-839c-fa163ed93e4f",
"value": "New Custom Field value 2"
}
],
[...]
PUT (update) a Contact
https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact
Alternately, you could instead use our Bulk Activities endpoints, which work similarly to uploading a spreadsheet within the UI, and only adds/updates the data that you provide:
V3 Bulk Activity - Import Contacts
https://v3.developer.constantcontact.com/api_guide/import_contacts.html
Please have a look and let us know if you have any other questions!
... View more