Contact Custom FieldsAdd Custom Field Data to a Contact
Add Custom Field Data to a Contact
Add Custom Field Data to a New Contact
After creating custom fields in the account, you can add them to a new contact in the request body when making a POST call to the /contacts endpoint.
Example POST Call
This example creates a new contact and adds the "Vehicle make and model" custom_field_id and corresponding value to the new contact resource.
POST
https://api.cc.email/v3/contactsEndpoint Requirements
User privileges: contacts:writeAuthorization scopes: contact_dataHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"email_address\": \n\t{\n\t\t\"address\": \"ddinapoli@example.com\",\n\t\t\"permission_to_send\": \"implicit\"\n\t},\n\t\"first_name\": \"David\",\n\t\"last_name\": \"DiNapoli\",\n\t\"create_source\": \"Account\",\n\t\"birthday_month\": 11,\n\t\"birthday_day\": 24,\n\t\"anniversary\": \"2006-11-15\",\n\t\"custom_fields\": \n\t[\n\t\t{\n\t\t\t\"custom_field_id\": \"{custom_field_id}\",\n\t\t\t\"value\": \"Tesla Model X\"\n\t\t}\n\t]\n}\t\n");
Request request = new Request.Builder()
.url("https://api.cc.email/v3/contacts?include=custom_fields")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer {access_token}")
.build();
Response response = client.newCall(request).execute();Response
{
"contact_id": "{contact_id}",
"email_address": {
"address": "ddinapoli@example.com",
"permission_to_send": "implicit",
"created_at": "2018-03-06T13:41:30-05:00",
"updated_at": "2018-03-06T13:41:30-05:00",
"opt_in_source": "Account",
"opt_in_date": "2018-03-06T13:41:30-05:00",
"confirm_status": "off"
},
"first_name": "David",
"last_name": "DiNapoli",
"birthday_month": 11,
"birthday_day": 24,
"anniversary": "2006-11-15",
"create_source": "Account",
"created_at": "2018-03-06T13:41:30-05:00",
"updated_at": "2018-03-06T13:41:30-05:00",
"custom_fields": [
{
"custom_field_id": "{custom_field_id}",
"value": "Tesla Model X"
}
]
}Add custom_field Data to Existing Contacts
Add custom_field data to existing contacts by including the custom_field subresource in a PUT call to update the contact resource.
Example PUT call
PUT
https://api.cc.email/v3/contacts/{contact_id}Endpoint Requirements
User privileges: contacts:writeAuthorization scopes: contact_dataOkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"email_address\": \n\t{\n\t\t\"address\": \"ddinapoli@example.com\",\n\t\t\"permission_to_send\": \"implicit\"\n\t},\n\t\"first_name\": \"David\",\n\t\"last_name\": \"DiNapoli\",\n\t\"update_source\": \"Account\",\n\t\"birthday_month\": 11,\n\t\"birthday_day\": 24,\n\t\"anniversary\": \"2006-11-15\",\n\t\"custom_fields\": \n\t[\n\t\t{\n\t\t\t\"custom_field_id\": \"{custom_field_id}\",\n\t\t\t\"value\": \"Ford 2017\"\n\t\t}\n\t]\n}\t\n");
Request request = new Request.Builder()
.url("https://api.cc.email/v3/contacts/{contact_id}")
.put(body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer {access_token}")
.addHeader("Cache-Control", "no-cache")
.build();
Response response = client.newCall(request).execute();Response
{
"contact_id": "{contact_id}",
"first_name": "David",
"last_name": "DiNapoli",
"birthday_month": 11,
"birthday_day": 24,
"anniversary": "2006-11-15",
"update_source": "Account",
"create_source": "Account",
"created_at": "2016-01-23T13:48:44.108Z",
"updated_at": "2018-03-06T14:50:44-05:00",
"email_address": {
"address": "ddinapoli@example.com",
"permission_to_send": "implicit",
"created_at": "2016-03-03T15:53:04.000Z",
"updated_at": "2016-03-03T15:56:29.000Z",
"opt_in_source": "Account",
"opt_in_date": "2016-01-23T13:48:44.108Z",
"confirm_status": "off"
},
"custom_fields": [
{
"custom_field_id": "{custom_field_id}",
"value": "Ford 2017"
}
]
}