Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Create Custom Field Definition



API Overview

api-overview page anchor

Custom Fields allow you to add extra information about your contacts to your contact database. With custom fields, you can create custom segments from your individual contacts or from your contact database that will dynamically update your content with the values for the individual contact receiving the email. Your custom fields are completely customizable to the use cases and user information that you need.

You can also manage your Custom Fields using the Custom Fields UI in the Marketing Campaigns App(link takes you to an external page). For more about creating Custom Fields, including a list of Reserved Fields, see our Custom Fields documentation.


POST/v3/marketing/field_definitions

Base url: https://api.sendgrid.com

This endpoint creates a new custom field definition.

Custom field definitions are created with the given name and field_type. Although field names are stored in a case-sensitive manner, all field names must be case-insensitively unique. This means you may create a field named CamelCase or camelcase, but not both. Additionally, a Custom Field name cannot collide with any Reserved Field names. You should save the returned id value in order to update or delete the field at a later date. You can have up to 500 custom fields.

The custom field name should be created using only alphanumeric characters (A-Z and 0-9) and underscores (_). Custom fields can only begin with letters A-Z or underscores (_). The field type can be date, text, or number fields. The field type is important for creating segments from your contact database.

Note: Creating a custom field that begins with a number will cause issues with sending in Marketing Campaigns.


Authentication

authentication page anchor
Property nameTypeRequiredDescription
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>
SchemaExample
Property nameTypeRequiredDescriptionChild properties
namestringrequired
Min length: 1Max length: 100

field_typeenum<string>required
Possible values:
TextNumberDate
200400
SchemaExample
Property nameTypeRequiredDescriptionChild properties
idstring

namestring
Min length: 1Max length: 100

field_typeenum<string>
Possible values:
TextNumberDate

_metadataobject

Create Custom Field Definition

create-custom-field-definition page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
curl

_22
const client = require('@sendgrid/client');
_22
client.setApiKey(process.env.SENDGRID_API_KEY);
_22
_22
const data = {
_22
"name": "custom_field_name",
_22
"field_type": "Text"
_22
};
_22
_22
const request = {
_22
url: `/v3/marketing/field_definitions`,
_22
method: 'POST',
_22
body: data
_22
}
_22
_22
client.request(request)
_22
.then(([response, body]) => {
_22
console.log(response.statusCode);
_22
console.log(response.body);
_22
})
_22
.catch(error => {
_22
console.error(error);
_22
});


Rate this page: