Skip to contentSkip to navigationSkip to topbar
On this page

Get List of Segments



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.


GET/v3/marketing/segments/2.0

Base url: https://api.sendgrid.com (The Twilio SendGrid v3 API)

This endpoint allows you to retrieve a list of segments.

The query param parent_list_ids is treated as a filter. Any match will be returned. Zero matches will return a response code of 200 with an empty results array.

parent_list_idsno_parent_list_ididsresult
emptyfalseemptyall segments values
list_idsfalseemptysegments filtered by list_ids values
list_idstrueemptysegments filtered by list_ids and segments with no parent list_ids empty
emptytrueemptysegments with no parent list_ids
anythinganythingidssegments with matching segment ids

Authentication

authentication page anchor
Property nameTypeRequiredDescription
authorizationstring
required
Default: Bearer <<YOUR_API_KEY_HERE>>
Property nameTypeRequiredDescription
idsarray[string]

Optional

A list of segment IDs to retrieve. When this parameter is included, the no_parent_list_ids and parent_list_ids parameters are ignored and only segments with given IDs are returned.


parentListIdsstring

Optional

A comma separated list up to 50 in size, to filter segments on. Only segments that have any of these list ids as the parent list will be retrieved. This is different from the parameter of the same name used when creating a segment.


noParentListIdboolean

Optional

If set to true, segments with an empty value of parent_list_id will be returned in the filter. If the value is not present, it defaults to 'false'.

Default: false
200400404500
Schema
Property nameTypeRequiredDescriptionChild properties
idstring<uuid>

Optional

ID assigned to the segment when created.

Min length: 36Max length: 36

namestring

Optional

Name of the segment.

Min length: 1Max length: 100

contactsCountinteger

Optional

Total number of contacts present in the segment


createdAtstring

Optional

ISO8601 timestamp of when the object was created


updatedAtstring

Optional

ISO8601 timestamp of when the object was last updated


sampleUpdatedAtstring

Optional

ISO8601 timestamp of when the samples were last updated


nextSampleUpdatestring

Optional

ISO8601 timestamp of when the samples will be next updated


parentListIdsarray[string]
unique

Optional

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


queryVersionstring

Optional

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.


Metadata_metadata

Optional


statussegment_status_response

Optional

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

Get List of SegmentsLink to code sample: Get List of Segments
1
const client = require("@sendgrid/client");
2
client.setApiKey(process.env.SENDGRID_API_KEY);
3
4
const request = {
5
url: `/v3/marketing/segments/2.0`,
6
method: "GET",
7
};
8
9
client
10
.request(request)
11
.then(([response, body]) => {
12
console.log(response.statusCode);
13
console.log(response.body);
14
})
15
.catch((error) => {
16
console.error(error);
17
});