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 = {5"name": "Last Name Miller",6"list_id": 4,7"conditions": [8{9"field": "last_name",10"value": "Miller",11"operator": "eq",12"and_or": ""13},14{15"field": "last_clicked",16"value": "01/02/2015",17"operator": "gt",18"and_or": "and"19},20{21"field": "clicks.campaign_identifier",22"value": "513",23"operator": "eq",24"and_or": "or"25}26],27"recipient_count": 123428};2930const request = {31url: `/v3/contactdb/segments`,32method: 'POST',33body: data34}3536client.request(request)37.then(([response, body]) => {38console.log(response.statusCode);39console.log(response.body);40})41.catch(error => {42console.error(error);43});