Got a 'How do I' question? Join 'Ask a Trainer' Monday to Friday, 11am to 4pm ET for instant help and pro tips!

Update a contact's Custom field value removes other custom field values

SOLVED
Go to solution
josephineo
Campaign Expert
0 Votes

The issue: update/adding values to one custom fields removes values to all other previously set custom fields.  How do add custom field values without the API clearing all other custom fields?

 

Background:

I have created three custom fields that are "dates".  These dates represent the dates when the user has taken actions (e.g., "registered" and "subscribed").  API put call to the contacts endpoint

 https://api.cc.email/v3/contacts/<<contact_id>>

with the custom fields JSON in the body does update the contact record, e.g.,  

"custom_fields": [{"custom_field_id": "161d4560-ff1f-11ed-8035-fa163e1233be","value": "5/31/2023"}] 

 

However, when a subsequent call to the contacts endpoint to add/update another custom field, does add the custom field value, but it deletes all other custom field values that were previously set. Here is the custom field request, e.g., 

"custom_fields": [{"custom_field_id": "eb96fd80-4434-11e9-86fd-d4ae529a863c","value": "6/1/2024"}] 

 

It's not my code.  I confirmed this behavior using the "try" capability in the developer reference: 

https://developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact

 

josephineo_0-1685552585774.png

 

1 ACCEPTED SOLUTION
Courtney_E
Moderator
0 Votes

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_membe...

 

{

  "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!

 

 

Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.

View solution in original post

2 REPLIES 2
Courtney_E
Moderator
0 Votes

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_membe...

 

{

  "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!

 

 

Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
josephineo
Campaign Expert
0 Votes

Thanks.  Seems easiest to use a JSON payload POSTed to the V3 Bulk Activity - Import Contacts URL.  That is one step vs GETting, parsing, editing, and PUTting the contact data. 

 

eg

 

{"import_data":[{"email":"dlang@example.com", "cf:subscription_start_date":"06/05/2023", "cf:subscription_end_date":"06/06/2024"}], "list_ids":["5cdc68f8-5bce-11e9-b67a-d4ae52754950","3def8714-3fbb-11ea-b726-d4ae529cddd3","67842e9e-c500-11e9-9e9a-d4ae529a863c"]}

 

Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up