Menu

Expand
Rate this page:

Segmenting Contacts V2

Segments are similar to contact lists, except they update dynamically over time as information stored about your contacts or the criteria used to define your segments changes. When you segment your audience, you are able to create personalized Automation emails and Single Sends that directly address the wants and needs of your particular audience.

The Marketing Campaigns Segments V2 API allows you to create, edit, and delete segments as well as retrieve a list of segments or an individual segment by ID.

Note that Twilio SendGrid checks for newly added or modified contacts who meet a segment's criteria on an hourly schedule. Only existing contacts who meet a segment's criteria will be included in the segment searches within 15 minutes.

Segments built using engagement data such as "was sent" or "clicked" will take approximately 30 minutes to begin populating.

Segment samples and counts are refreshed approximately once per hour; they do not update immediately. If no contacts are added to or removed from a segment since the last refresh, the sample and UI count displayed will be refreshed at increasing time intervals with a maximum sample and count refresh delay of 24 hours.

Create Segment

POST /v3/marketing/segments/2.0

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

Segment name has to be unique. A user can not create a new segment with an existing segment name.

Authentication

  • API Key

Headers

Authorization
string
default: Bearer <<YOUR_API_KEY_HERE>>
required

Request Body

object
name
string

Name of the segment.

maxLength: 100minLength: 1
required
parent_list_ids
array[string]

The array of list ids to filter contacts on when building this segment. It allows only one such list id for now. We will support more in future

uniqueItems: True
query_dsl
string

SQL query which will filter contacts based on the conditions provided

required

Responses

object
id
string

ID assigned to the segment when created.

format: uuidmaxLength: 36minLength: 36
required
name
string

Name of the segment.

maxLength: 100minLength: 1
required
query_dsl
string

SQL query which will filter contacts based on the conditions provided

required
contacts_count
integer

Total number of contacts present in the segment

required
contacts_sample
array[object]

A subset of all contacts that are in this segment

required
id
string

ID assigned to a contact when added to the system.

format: uuidmaxLength: 36pattern: [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}
required
email
string

Email of the contact. This is a reserved field.

format: emailmaxLength: 254minLength: 3
required
alternate_emails
array[string]

Alternate emails of the contact. This is a reserved field.

minItems: 0uniqueItems: True
required
first_name
string

First name of the contact. This is a reserved field.

minLength: 1
required
last_name
string

Last name of the contact. This is a reserved field.

minLength: 1
required
address_line_1
string

First line of address of the contact. This is a reserved field.

minLength: 0
required
address_line_2
string

Second line of address of the contact. This is a reserved field.

minLength: 0
required
city
string

City associated with the contact. This is a reserved field.

minLength: 0pattern: ^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$
required
state_province_region
string

State associated with the contact. This is a reserved field.

minLength: 0
required
postal_code
integer

Zipcode associated with the address of the contact. This is a reserved field.

required
country
string

Country associated with the address of the contact. This is a reserved field.

minLength: 0
required
list_ids
array[string]

IDs of all lists the contact is part of

uniqueItems: True
custom_fields
object

The user may choose to create up to 120 custom fields or none at all. This is not a reserved field.

required
custom_field_name1
string
minLength: 0
custom_field_name2
string
minLength: 0
string
segment_ids
array[string]

IDs of all segments the contact is part of

uniqueItems: True
created_at
string

ISO8601 timestamp of when the object was created

required
updated_at
string

ISO8601 timestamp of when the object was last updated

required
sample_updated_at
string

ISO8601 timestamp of when the samples were last updated

required
next_sample_update
string

ISO8601 timestamp of when the samples will be next updated

required
parent_list_ids
array[string]

The array of list ids to filter contacts on when building this segment. It allows only one such list id for now. We will support more in future

uniqueItems: True
required
query_version
string

If not set, segment contains a Query for use with Segment v1 APIs. If set to '2', segment contains a SQL query for use in v2.

required
status
object

Segment status indicates whether the segment's contacts will be updated periodically

required
query_validation
string

Status of query validation. PENDING, VALID, or INVALID

required
error_message
string

Describes any errors that were encountered during query validation

refreshes_used
integer

The number of times a segment has been manually refreshed since start of today in the user's timezone.

max_refreshes
integer

The maximum number of manual refreshes allowed per day for this segment. Currently, only 2 are allowed.

last_refreshed_at
string

The ISO8601 timestamp when the segment was last refreshed in UTC time.

object

If the request is incorrect, an array of errors will be returned.

errors
array[object]
required
field
string

the field in the request body that is incorrect

required
message
string

a description of what is specifically wrong with the field passed in the request

required
No response body.
No response body.
object

If the request is incorrect, an array of errors will be returned.

errors
array[object]
required
field
string

the field in the request body that is incorrect

required
message
string

a description of what is specifically wrong with the field passed in the request

required
Loading Code Sample...
        
        

        Create Segment

        Rate this page:

        Need some help?

        We all do sometimes. Get help now from the Twilio SendGrid Support Team.

        Running into a coding hurdle? Lean on the wisdom of the crowd by browsing the SendGrid tag on Stack Overflow or visiting Twilio's Stack Overflow Collective.

        Loading Code Sample...
              
              
              

              Thank you for your feedback!

              Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

              Sending your feedback...
              🎉 Thank you for your feedback!
              Something went wrong. Please try again.

              Thanks for your feedback!

              thanks-feedback-gif