MessagePipedocs
API Reference

Segments

Dynamic and static audience groups you target a campaign at, with counts, samples and members over the API.

A segment is a group of contacts a campaign can be sent to. A dynamic segment is a rule tree that is evaluated when you count it or start a campaign; a static segment is a hand-picked list of members. Segments, counts and previews cost 0 credits; credits are spent only when a campaign message is sent.

OperationScopeRate classIdempotency-Key
GET /v1/segmentssegments:readread
GET /v1/segments/schemasegments:readread
GET /v1/segments/{id}segments:readread
GET /v1/segments/{id}/countsegments:readread
GET /v1/segments/{id}/memberssegments:readread
GET /v1/segments/{id}/samplesegments:writeread
POST /v1/segments/previewsegments:readread
POST /v1/segments/validatesegments:writeread
POST /v1/segmentssegments:writewriteoptional
PATCH /v1/segments/{id}segments:writewriteoptional
DELETE /v1/segments/{id}segments:writewriteoptional
POST /v1/segments/{id}/memberssegments:writewriteoptional
DELETE /v1/segments/{id}/memberssegments:writewriteoptional

The sample returns twenty contacts' personal data, which the dashboard shows to marketers only, so it needs the write scope. The member list masks personal data for a viewer-level key.

Rule language

A rule tree is JSON. Every node is an object with exactly one key:

{"all": [
  {"topic": {"id": "top_...", "state": "subscribed"}},
  {"attribute": {"name": "plan", "op": "eq", "value": "pro"}},
  {"not": {"tag": {"op": "has", "value": "do-not-promote"}}}
]}

Combinators are all, any and not. Leaves are attribute, tag, topic, consent, created_at and field. There is no raw SQL: attribute names are checked against your workspace's attribute definitions (read them from GET /v1/segments/schema), and values are bound parameters. A tree is limited in depth (6) and size (100 nodes). POST /v1/segments/validate returns every problem with a path to the offending node.

Create, count, use

curl https://api.messagepipe.dev/v1/segments \
  -H "Authorization: Bearer mp_live_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pro subscribers",
    "type": "dynamic",
    "rules": {"all": [{"topic": {"id": "top_xxxxxxxx", "state": "subscribed"}},
                      {"attribute": {"name": "plan", "op": "eq", "value": "pro"}}]}
  }'

curl https://api.messagepipe.dev/v1/segments/seg_xxxxxxxx/count \
  -H "Authorization: Bearer mp_live_xxxxxxxxxxxxxxxx"

The count is how many contacts match the rules now. The campaign's pre-flight reports the audience it will actually send to, and suppressed addresses are still checked, one by one, at send time. Pass the segment's id as segment_id when you create a campaign.