Skip to main content
Segments group contacts based on shared attributes or behaviors. There are two types:
  • Dynamic — membership is evaluated on-the-fly using filter conditions against contact data and event history.
  • Static — membership is managed manually by adding or removing specific email addresses.
All segment endpoints require a secret key (sk_*).

Filter condition schema

Dynamic segments use a nested FilterCondition object to define who belongs to the segment.
{
  "logic": "AND",
  "groups": [
    {
      "filters": [
        {
          "field": "data.plan",
          "operator": "equals",
          "value": "premium"
        },
        {
          "field": "subscribed",
          "operator": "equals",
          "value": true
        }
      ]
    }
  ]
}

Available operators

OperatorDescription
equalsExact match
notEqualsDoes not match
containsString contains value
notContainsString does not contain value
greaterThanNumeric greater than
lessThanNumeric less than
greaterThanOrEqualNumeric greater than or equal
lessThanOrEqualNumeric less than or equal
existsField is present and non-null
notExistsField is absent or null
withinDate is within the last N unit (days/hours/minutes)
olderThanDate is older than N unit
triggeredEvent was tracked at least once
triggeredWithinEvent was tracked within the last N unit
triggeredOlderThanEvent was last tracked more than N unit ago
notTriggeredEvent has never been tracked
For time-based operators (within, olderThan, triggeredWithin, triggeredOlderThan) also provide:
  • value — the numeric amount
  • unit — one of days, hours, or minutes

List segments

GET /segments Returns all segments for the authenticated project.
Example
curl --request GET \
  --url https://next-api.useplunk.com/segments \
  --header 'Authorization: Bearer sk_live_yourkey'
200
[
  {
    "id": "clx_seg_abc123",
    "name": "Premium Users",
    "type": "DYNAMIC",
    "memberCount": 843,
    "trackMembership": true,
    "createdAt": "2024-01-01T00:00:00.000Z"
  }
]

Create segment

POST /segments Creates a new segment.

Body parameters

name
string
required
Segment name.
type
string
default:"DYNAMIC"
Segment type: DYNAMIC or STATIC.
condition
object
Filter condition defining dynamic membership. Required when type is DYNAMIC.
description
string
Optional description.
trackMembership
boolean
default:"false"
When true, Plunk tracks when contacts enter and exit this segment and fires segment.<slug>.entry / segment.<slug>.exit system events that can trigger workflows.
curl --request POST \
  --url https://next-api.useplunk.com/segments \
  --header 'Authorization: Bearer sk_live_yourkey' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Active Premium Users",
    "type": "DYNAMIC",
    "condition": {
      "logic": "AND",
      "groups": [
        {
          "filters": [
            { "field": "data.plan", "operator": "equals", "value": "premium" },
            { "field": "subscribed", "operator": "equals", "value": true }
          ]
        }
      ]
    },
    "trackMembership": true
  }'

Get segment

GET /segments/:id Retrieves a single segment by ID, including its current member count.

Path parameters

id
string
required
The segment ID.
Example
curl --request GET \
  --url https://next-api.useplunk.com/segments/clx_seg_abc123 \
  --header 'Authorization: Bearer sk_live_yourkey'

Update segment

PATCH /segments/:id Updates a segment’s name, description, filter condition, or membership tracking setting.

Path parameters

id
string
required
The segment ID.

Body parameters

name
string
Segment name.
description
string
Segment description.
condition
object
Updated filter condition object.
trackMembership
boolean
Enable or disable membership tracking.
Example
curl --request PATCH \
  --url https://next-api.useplunk.com/segments/clx_seg_abc123 \
  --header 'Authorization: Bearer sk_live_yourkey' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Active Premium Users (Updated)",
    "trackMembership": false
  }'

Delete segment

DELETE /segments/:id Permanently deletes a segment.
Deleting a segment that is used by a campaign or workflow will break those references.

Path parameters

id
string
required
The segment ID.
Returns 204 No Content on success.
Example
curl --request DELETE \
  --url https://next-api.useplunk.com/segments/clx_seg_abc123 \
  --header 'Authorization: Bearer sk_live_yourkey'

List contacts in segment

GET /segments/:id/contacts Returns a paginated list of contacts that currently belong to the segment.

Path parameters

id
string
required
The segment ID.

Query parameters

page
number
default:"1"
Page number (1-indexed).
pageSize
number
default:"20"
Contacts per page. Maximum 100.
Example
curl --request GET \
  --url 'https://next-api.useplunk.com/segments/clx_seg_abc123/contacts?page=1&pageSize=50' \
  --header 'Authorization: Bearer sk_live_yourkey'

Add contacts to static segment

POST /segments/:id/members Adds contacts to a static segment by email address. Creates any contacts that do not yet exist.

Path parameters

id
string
required
The segment ID. The segment must be of type STATIC.

Body parameters

emails
string[]
required
Array of email addresses to add to the segment.
Example
curl --request POST \
  --url https://next-api.useplunk.com/segments/clx_seg_abc123/members \
  --header 'Authorization: Bearer sk_live_yourkey' \
  --header 'Content-Type: application/json' \
  --data '{
    "emails": ["[email protected]", "[email protected]"]
  }'

Remove contacts from static segment

DELETE /segments/:id/members Removes contacts from a static segment by email address.

Path parameters

id
string
required
The segment ID. The segment must be of type STATIC.

Body parameters

emails
string[]
required
Array of email addresses to remove from the segment.
Example
curl --request DELETE \
  --url https://next-api.useplunk.com/segments/clx_seg_abc123/members \
  --header 'Authorization: Bearer sk_live_yourkey' \
  --header 'Content-Type: application/json' \
  --data '{
    "emails": ["[email protected]"]
  }'

Build docs developers (and LLMs) love