Skip to main content

Create Segment

Create a new segment in your workspace. Segments are dynamic groups of contacts defined by a set of filter rules.


Endpoint

POST https://api.campaignlark.com/v1/segments

Request Body

FieldTypeRequiredDescription
namestringrequiredSegment name. 1–64 characters.
filtersobjectrequiredFilter configuration object.
filters.conditionstringrequiredLogical operator to combine filters. Must be AND or OR.
filters.filtersarrayrequiredArray of filter objects. At least one filter is required.

Sample Request

POST https://api.campaignlark.com/v1/segments
Content-Type: application/json

{
"name": "Active Subscribers",
"filters": {
"condition": "AND",
"filters": [
{
"type": "field",
"field_id": 1,
"operator": "eq",
"value": "test@example.com"
}
]
}
}

Filter Types

Each filter object must include a type field that determines its valid operators and value format.

field — Filter by contact field value

Filters contacts based on the value of a specific contact field.

PropertyTypeRequiredDescription
typestringrequiredMust be field.
field_idintegerrequiredThe ID of the field to filter on. Must exist in the workspace.
operatorstringrequiredComparison operator. Valid operators depend on the field type (see below).
valuevariesrequiredThe value to compare against.

Operators by field type:

Field TypeValid Operators
TEXTeq, ne, contains, not_contains, starts_with, ends_with, in, not_in
NUMBEReq, ne, gt, lt, gte, lte
BOOLEANeq, ne
DATEeq, ne, gt, lt, gte, lte
DROPDOWN_SINGLEeq, ne, in, not_in
DROPDOWN_MULTIPLEeq, ne, contains, not_contains
COUNTRYeq, ne, in, not_in

Example:

{
"type": "field",
"field_id": 1,
"operator": "eq",
"value": "test@example.com"
}

tags — Filter by contact tags

Filters contacts based on their assigned tags.

PropertyTypeRequiredDescription
typestringrequiredMust be tags.
operatorstringrequiredOne of eq, ne, contains, not_contains.
valuearray of integersrequiredArray of tag IDs. All referenced tag IDs must exist in the workspace.

Example:

{
"type": "tags",
"operator": "contains",
"value": [1, 2]
}

open_rate — Filter by open rate

Filters contacts based on their email open rate percentage.

PropertyTypeRequiredDescription
typestringrequiredMust be open_rate.
operatorstringrequiredOne of eq, gt, lt, gte, lte.
valueintegerrequiredPercentage value between 0 and 100.

Example:

{
"type": "open_rate",
"operator": "gte",
"value": 50
}

click_rate — Filter by click rate

Filters contacts based on their email click rate percentage.

PropertyTypeRequiredDescription
typestringrequiredMust be click_rate.
operatorstringrequiredOne of eq, gt, lt, gte, lte.
valueintegerrequiredPercentage value between 0 and 100.

Example:

{
"type": "click_rate",
"operator": "lte",
"value": 25
}

last_activity — Filter by last activity date

Filters contacts based on their most recent activity. A contact matches if their last open or last click satisfies the condition.

PropertyTypeRequiredDescription
typestringrequiredMust be last_activity.
operatorstringrequiredOne of is_after, is_before, within_last_days.
valuevariesrequiredValue format depends on the operator (see below).

Operators:

OperatorValue TypeDescription
is_afterstring (RFC 3339)Matches contacts whose last open or click occurred after the given date.
is_beforestring (RFC 3339)Matches contacts whose last open or click occurred before the given date.
within_last_daysinteger (> 0)Matches contacts whose last open or click occurred within the last N days.

Examples:

{ "type": "last_activity", "operator": "is_after", "value": "2026-03-01T00:00:00Z" }
{ "type": "last_activity", "operator": "within_last_days", "value": 30 }

Response

Success — 201 Created

Asynchronously queues segment member calculation after creation.

{
"data": {
"id": 1,
"name": "Active Subscribers",
"filters": {
"condition": "AND",
"filters": [
{
"type": "field",
"field_id": 1,
"operator": "eq",
"value": "test@example.com"
}
]
},
"contact_count": 0,
"created_at": "2026-04-09T02:20:00Z",
"updated_at": "2026-04-09T02:20:00Z"
}
}

Errors

StatusMessageCause
400Please provide a name for this segmentname is missing.
400Segment name must be 64 characters or lessname exceeds 64 characters.
400Filter condition must be AND or ORfilters.condition is missing or invalid.
400At least one filter is requiredfilters.filters is empty.
400Filter #N: Please provide a valid field_idA field filter is missing field_id.
400Filter #N: The specified field_id does not existThe referenced field does not exist in the workspace.
400Filter #N: Invalid operator for field filter. Must be one of: ...Invalid operator for the given field type.
400Filter #N: Tags filter value must be an array of tag IDs.tags filter value is not a valid array of integers.
400Filter #N: Invalid operator for tags filter. Must be one of: ...Invalid operator for a tags filter.
400Filter #N: Invalid operator for last activity filter. Must be one of: ...Invalid operator for a last_activity filter.
400Filter #N: Value must be between 0 and 100open_rate or click_rate filter value is out of range.
400Billing limit errorWorkspace plan does not allow additional segments.