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

Create Segment



API Overview

api-overview page anchor

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.


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

authentication page anchor
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>
Schema
namestringrequired

Name of the segment.

Min length: 1Max length: 100

parent_list_idsarray[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


query_dslstringrequired

SQL query which will filter contacts based on the conditions provided

201400404429500
Schema
idstring<uuid>

ID assigned to the segment when created.

Min length: 36Max length: 36

namestring

Name of the segment.

Min length: 1Max length: 100

query_dslstring

SQL query which will filter contacts based on the conditions provided


contacts_countinteger

Total number of contacts present in the segment


contacts_samplearray[object]

A subset of all contacts that are in this segment


created_atstring

ISO8601 timestamp of when the object was created


updated_atstring

ISO8601 timestamp of when the object was last updated


sample_updated_atstring

ISO8601 timestamp of when the samples were last updated


next_sample_updatestring

ISO8601 timestamp of when the samples will be next updated


parent_list_idsarray[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


query_versionstring

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.


statusobject

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


refreshes_usedinteger

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


max_refreshesinteger

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


last_refreshed_atstring

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

Create Segment

create-segment 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": "Miss Christine Morgan",
_22
"query_dsl": "ZGkrHSypTsudrGkmdpJJ"
_22
};
_22
_22
const request = {
_22
url: `/v3/marketing/segments/2.0`,
_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: