Use the `custom_field` subresource to store custom content for each contact in a user's account.

Add custom_field Data when Creating a New Contact

Once you’ve created the custom fields in the account, you can then add custom_field data to new contacts in the POST /contacts request body when creating a new contact.

Example POST Call

This example creates a new contact and adds the custom_field “Vehicle make and model” and corresponding value to the new contact resource.

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

Endpoint Requirements

Authorization scopes: contact_data

HttpClient 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();
  curl -X POST \
  https://api.cc.email/v3/contacts?include=custom_fields \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "email_address": 
    {
      "address": "ddinapoli@example.com",
      "permission_to_send": "implicit"
    },
    "first_name": "David",
    "last_name": "DiNapoli",
    "create_source": "Account",
    "birthday_month": 11,
    "birthday_day": 24,
    "anniversary": "2006-11-15",
    "custom_fields": 
    [
      {
        "custom_field_id": "{custom_field_id}",
        "value": "Tesla Model X"
      }
    ]
  }'
  <?php

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

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

$request->setBody('{
  "email_address": 
  {
    "address": "ddinapoli@example.com",
    "permission_to_send": "implicit"
  },
  "first_name": "David",
  "last_name": "DiNapoli",
  "create_source": "Account",
  "birthday_month": 11,
  "birthday_day": 24,
  "anniversary": "2006-11-15",
  "custom_fields": 
  [
    {
      "custom_field_id": "{custom_field_id}",
      "value": "Tesla Model X"
    }
  ]
} 
');

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

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

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

Authorization scopes: contact_data

OkHttpClient 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();
curl -X PUT \
  https://api.cc.email/v3/contacts/{contact_id} \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "email_address": 
  {
    "address": "ddinapoli@example.com",
    "permission_to_send": "implicit"
  },
  "first_name": "David",
  "last_name": "DiNapoli",
  "update_source": "Account",
  "birthday_month": 11,
  "birthday_day": 24,
  "anniversary": "2006-11-15",
  "custom_fields": 
  [
    {
      "custom_field_id": "{custom_field_id}",
      "value": "Ford 2017"
    }
  ]
} 
'
<?php

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

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

$request->setBody('{
  "email_address": 
  {
    "address": "ddinapoli@example.com",
    "permission_to_send": "implicit"
  },
  "first_name": "David",
  "last_name": "DiNapoli",
  "update_source": "Account",
  "birthday_month": 11,
  "birthday_day": 24,
  "anniversary": "2006-11-15",
  "custom_fields": [
      {
        "custom_field_id": "{custom_field_id}",
        "value": "Ford 2017"
      }
    ]
} 
');

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

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

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"
      }
    ]
}