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

Get Segment by ID



API Overview

api-overview page anchor
(information)

Info

Segmentation V2 APIs are now available! See the Getting Started guide to find out what new features are available.

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 API allows you to create, edit, and delete segments as well as retrieve a list of segments or an individual segment by ID.

(information)

Info

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.

For more information on creating segments with the Twilio SendGrid Marketing Campaigns UI see "Segmenting your Contacts."

For help with Segmentation Query Language, see our Segmentation Query Language reference

(warning)

Warning

The Segmentation v1 API was deprecated on December 31, 2022. Following deprecation, all segments created in the Marketing Campaigns user interface began using the Segmentation v2 API.

To enable manual migration and data retrieval, the GET and DELETE v1 API endpoints will remain available. The POST (create) and PATCH (update) v1 endpoints were removed on January 31, 2023 because it is no longer possible to create new v1 segments or modify existing ones. See our Segmentation v1 to v2 upgrade instructions to manually migrate your segments to the v2 API.


GET/v3/marketing/segments/{segment_id}

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

This endpoint allows you to retrieve a single segment by ID.


Authentication

authentication page anchor
Property nameTypeRequiredDescription
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>
Property nameTypeRequiredDescription
segment_idstring<uuid>required
Min length: 36Max length: 36
Property nameTypeRequiredDescription
query_jsonbooleanOptional

Defaults to false. Set to true to return the parsed SQL AST as a JSON object in the field query_json

200401403404500
SchemaExample
Property nameTypeRequiredDescriptionChild properties
idstring<uuid>
Min length: 36Max length: 36

contacts_countinteger

created_atstring<date-time>

ISO8601 of created timestamp


namestring

Name of the segment.

Min length: 1Max length: 100

parent_list_idstring<uuid>

The id of the list if this segment is a child of a list. This implies the query AND CONTAINS(list_ids, ${parent_list_id})

Min length: 36Max length: 36

sample_updated_atstring<date-time>

ISO8601 timestamp the sample was last updated


updated_atstring<date-time>

ISO8601 timestamp the object was last updated


next_sample_updatestring

ISO8601 string that is equal to sample_updated_at plus an internally calculated offset that depends on how often contacts enter or exit segments as the scheduled pipeline updates the samples.


contacts_samplearray[object]

query_jsonobject

AST representation of the query DSL


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_dslstring

SQL query which will filter contacts based on the conditions provided

Get Segment by ID

get-segment-by-id page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
curl

_19
const client = require('@sendgrid/client');
_19
client.setApiKey(process.env.SENDGRID_API_KEY);
_19
_19
const segment_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";
_19
_19
const request = {
_19
url: `/v3/marketing/segments/${segment_id}`,
_19
method: 'GET',
_19
_19
}
_19
_19
client.request(request)
_19
.then(([response, body]) => {
_19
console.log(response.statusCode);
_19
console.log(response.body);
_19
})
_19
.catch(error => {
_19
console.error(error);
_19
});


Rate this page: