Describes how to create a new custom field, and to update an existing custom field.

Create a new custom_field

Make a POST call to the /contact_custom_fields endpoint. Provide:

  • a label (name) describing the custom_field category, note that each label must be unique.
  • the custom_field data type, either string for text, or date for date-based data

Example POST Call - add a new custom_field

This example creates a custom field for storing the type of vehicle a contact owns. The auto-repair facility will use this new custom field along with an existing vehicle_year custom field to include the contact’s vehicle information in email campaigns.

POST https://api.cc.email/v3/contact_custom_fields

Endpoint Requirements

User privileges: contacts:write

Authorization scopes: contact_data

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n  \"label\": \"Vehicle make and model\",\r\n  \"type\": \"string\"\r\n}");
Request request = new Request.Builder()
  .url("https://api.cc.email/v3/contact_custom_fields")
  .post(body)
  .addHeader("Accept", "application/json")
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer {access_token}")
  .build();

Response response = client.newCall(request).execute();
curl -X POST \
  https://api.cc.email/v3/contact_custom_fields \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Content-Type: application/json' \
  -d '{
  "label": "Vehicle make and model year",
  "type": "string"
}'
<?php

$request = new HttpRequest();
$request->setUrl('https://api.cc.email/v3/contact_custom_fields');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'Authorization' => 'Bearer {access_token}',
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
));

$request->setBody('{
  "label": "Vehicle make and model",
  "type": "string"
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

Response

{
  "custom_field_id": "{custom_field_id}",
  "label": "Vehicle make and model",
  "name": "vehicle_make_and_model",
  "type": "string",
  "updated_at": "2016-03-03T15:53:04.000Z",
  "created_at": "2016-03-03T15:53:04.000Z"
}

Try it! Create a custom_field

Update an existing custom_field

You can update the label or type of an existing custom_field.

Example PUT Call

PUT https://api.cc.email/v3/contact_custom_fields/{custom_field_id}

Endpoint Requirements

User privileges: contacts:write

Authorization scopes: contact_data

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"label\": \"date of purchase or lease\",\n    \"type\": \"date\"\n}");
Request request = new Request.Builder()
  .url("https://api.cc.email/v3/contact_custom_fields/{custom_field_id}")
  .put(body)
  .addHeader("Accept", "application/json")
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer {access_token}")
  .build();

Response response = client.newCall(request).execute();
curl -X PUT \
  https://api.cc.email/v3/contact_custom_fields/{custom_field_id} \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "label": "purchase or lease date",
    "type": "date"
}'
<?php

$request = new HttpRequest();
$request->setUrl('https://api.cc.email/v3/contact_custom_fields/{custom_field_id}');
$request->setMethod(HTTP_METH_PUT);

$request->setHeaders(array(
  'Authorization' => 'Bearer {access_token}',
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
));

$request->setBody('{
    "label": "purchase or lease date",
    "type": "date"
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

Response

{
    "custom_field_id": "{custom_field_id}",
    "label": "purchase or lease date",
    "name": "purchase_or_lease_date",
    "type": "date",
    "updated_at": "2018-06-25T17:01:08-04:00",
    "created_at": "2015-02-02T15:14:16-05:00"
}