Skip to contentSkip to navigationSkip to topbar
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 (The Twilio SendGrid v3 API)

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>>
Encoding type:application/json
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 DefinitionLink to code sample: Create Custom Field Definition
1
const client = require('@sendgrid/client');
2
client.setApiKey(process.env.SENDGRID_API_KEY);
3
4
const data = {
5
"name": "custom_field_name",
6
"field_type": "Text"
7
};
8
9
const request = {
10
url: `/v3/marketing/field_definitions`,
11
method: 'POST',
12
body: data
13
}
14
15
client.request(request)
16
.then(([response, body]) => {
17
console.log(response.statusCode);
18
console.log(response.body);
19
})
20
.catch(error => {
21
console.error(error);
22
});

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.