Segments
Create, update, delete, and query Segments in SendGrid.
Table-Specific Information
Select
You can retrieve all the segments or filter them by Id.
SELECT * FROM Segments SELECT * FROM Segments WHERE Id = '1'
Insert
A Segment divides Recipients by certain criteria. To specify these criteria use the ConditionsField columns and the Id of the List to apply these criteria to.
The ConditionsAndOr columns connect the given Field with the previous one.
INSERT INTO Segments(Name, ListId, ConditionsField1, ConditionsValue1, ConditionsOperator1, ConditionsAndOr1, ConditionsField2, ConditionsValue2, ConditionsOperator2, ConditionsAndOr2) VALUES ("New Segment", 123, 'age', '20', '>', '', 'age', '30', '<', 'and')
The statement above creates Segments containing Recipients between age 20 and 30.
Update
You can update the name or the conditions. Since the whole set will be overwritten, specify a full set.
UPDATE Segments Set Name='Name Updated', ConditionsField1 = 'age', ConditionsOperator1 = '<=', ConditionsAndOr1 = '', ConditionsValue1 = '30' WHERE Id = '123'
Delete
You can only delete Segments by Id:
DELETE FROM Segments WHERE Id = '123'
Columns
Name | Type | ReadOnly | References | Description |
Id [KEY] | Integer | True |
The Id of the segment. | |
Name | String | False |
The name of the segment. | |
ListId | Integer | False |
The Id of the list associated with the segment. | |
RecipientCount | Integer | True |
The recipient count of the segment. | |
ConditionsField1 | String | False |
Field name for the first condition. | |
ConditionsValue1 | String | False |
Field value for the first condition. | |
ConditionsOperator1 | String | False |
Condition operator for the first condition. | |
ConditionsAndOr1 | String | False |
How to connect to the previous condition. Allowed values are AND or OR. | |
ConditionsField2 | String | False |
Field name for the second condition. | |
ConditionsValue2 | String | False |
Field value for the second condition. | |
ConditionsOperator2 | String | False |
Condition operator for the second condition. | |
ConditionsAndOr2 | String | False |
How to connect to the previous condition. Allowed values are AND or OR. | |
ConditionsField3 | String | False |
Field name for the third condition. | |
ConditionsValue3 | String | False |
Field value for the third condition. | |
ConditionsOperator3 | String | False |
Condition operator for the third condition. | |
ConditionsAndOr3 | String | False |
How to connect to the previous condition. Allowed values are AND or OR. | |
ConditionsField4 | String | False |
Field name for the fourth condition. | |
ConditionsValue4 | String | False |
Field value for the fourth condition. | |
ConditionsOperator4 | String | False |
Condition operator for the fourth condition. | |
ConditionsAndOr4 | String | False |
How to connect to the previous condition. Allowed values are AND or OR. | |
ConditionsField5 | String | False |
Field name for the fifth condition. | |
ConditionsValue5 | String | False |
Field value for the fifth condition. | |
ConditionsOperator5 | String | False |
Condition operator for the fifth condition. | |
ConditionsAndOr5 | String | False |
How to connect to the previous condition. Allowed values are AND or OR. |