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.
| Operation | Scope | Rate class | Idempotency-Key |
|---|---|---|---|
GET /v1/segments | segments:read | read | |
GET /v1/segments/schema | segments:read | read | |
GET /v1/segments/{id} | segments:read | read | |
GET /v1/segments/{id}/count | segments:read | read | |
GET /v1/segments/{id}/members | segments:read | read | |
GET /v1/segments/{id}/sample | segments:write | read | |
POST /v1/segments/preview | segments:read | read | |
POST /v1/segments/validate | segments:write | read | |
POST /v1/segments | segments:write | write | optional |
PATCH /v1/segments/{id} | segments:write | write | optional |
DELETE /v1/segments/{id} | segments:write | write | optional |
POST /v1/segments/{id}/members | segments:write | write | optional |
DELETE /v1/segments/{id}/members | segments:write | write | optional |
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.