You are viewing the Legacy Marketing Campaigns API reference. For guidance migrating to the current version of Marketing Campaigns, see Migrating from Legacy Marketing Campaigns
For the most up-to-date information on the Segments API, please visit the new Marketing Campaigns Segments v2 API.
The Segments API allows you to create and manage segments for your contacts. Segments are used to group contacts based on conditions you set. For example, you might create a segment for contacts who have opened a certain number of your emails, or for contacts who have not opened any of your emails in the last 30 days.
This endpoint allows you to create a new segment.
Valid operators for create and update depend on the type of the field for which you are searching.
Dates
Text
Numbers
Email Clicks and Opens
All field values must be a string.
Conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either clicks.campaign_identifier
or opens.campaign_identifier
.
The condition value should be a string containing the id of a completed campaign.
The conditions list may contain multiple conditions, joined by an "and" or "or" in the "and_or" field.
The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or".
Bearer <<YOUR_API_KEY_HERE>>
The on-behalf-of
header allows you to make API calls from a parent account on behalf of the parent's Subusers or customer accounts. You will use the parent account's API key when using this header. When making a call on behalf of a customer account, the property value should be "account-id" followed by the customer account's ID (e.g., on-behalf-of: account-id <account-id>
). When making a call on behalf of a Subuser, the property value should be the Subuser's username (e.g., on-behalf-of: <subuser-username>
). See On Behalf Of for more information.
application/json
The name of this segment.
The list id from which to make this segment. Not including this ID will mean your segment is created from the main contactdb rather than a list.
The conditions for a recipient to be included in this segment.
The count of recipients in this list. This is not included on creation of segments.
The ID of the segment.
The name of this segment.
The list id from which to make this segment. Not including this ID will mean your segment is created from the main contactdb rather than a list.
The conditions for a recipient to be included in this segment.
The count of recipients in this list. This is not included on creation of segments.
1const client = require("@sendgrid/client");2client.setApiKey(process.env.SENDGRID_API_KEY);34const data = {5name: "Last Name Miller",6list_id: 4,7conditions: [8{9field: "last_name",10value: "Miller",11operator: "eq",12and_or: "",13},14{15field: "last_clicked",16value: "01/02/2015",17operator: "gt",18and_or: "and",19},20{21field: "clicks.campaign_identifier",22value: "513",23operator: "eq",24and_or: "or",25},26],27recipient_count: 1234,28};2930const request = {31url: `/v3/contactdb/segments`,32method: "POST",33body: data,34};3536client37.request(request)38.then(([response, body]) => {39console.log(response.statusCode);40console.log(response.body);41})42.catch((error) => {43console.error(error);44});