Skip to content

Segments

Segments define audiences from pass attributes, custom fields, and user behavior. They are evaluated on demand (no stored membership) and are the primary way to target campaigns.

Auth: All segment endpoints require a Bearer token. Workspace-scoped routes (/workspace/:workspaceId/segments) and entity routes (/segments/:id/...) require the caller to be a member of the owning workspace. The custom-field helper routes resolve the workspace from the workspace_id query parameter; the filter-test and union routes resolve it from the request body.

bash
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json

Segment Structure

typescript
interface Segment {
  id: string;
  workspace_id: string;
  name: string;
  description?: string;
  filters: SegmentFilter[];
}

interface SegmentFilter {
  id?: string;
  filter_type:
    | 'all'
    | 'template'
    | 'project'
    | 'custom_field'
    | 'client_custom_field'
    | 'wallet_balance'
    | 'tier'
    | 'event_count'
    | 'event_sum'
    | 'field_sum'
    | 'event_recency';
  filter_config: Record<string, any>;
}

Multiple filters on a segment are combined with AND logic. See Filters for each filter_type's config.

Reference Pages

  • CRUD & evaluation — list, create, get, update, delete, duplicate, preview, passes, clients, calculate, client-count
  • Filters & helpers — filter types, test-filters, union, custom-field name/value discovery

Endpoint Index

MethodEndpointPage
GET/wallethero-api/workspace/:workspaceId/segmentscrud
POST/wallethero-api/workspace/:workspaceId/segmentscrud
GET/wallethero-api/segments/:idcrud
PATCH/wallethero-api/segments/:idcrud
DELETE/wallethero-api/segments/:idcrud
POST/wallethero-api/segments/:id/duplicatecrud
POST/wallethero-api/segments/:id/calculatecrud
GET/wallethero-api/segments/:id/previewcrud
GET/wallethero-api/segments/:id/passescrud
GET/wallethero-api/segments/:id/clientscrud
GET/wallethero-api/segments/:id/client-countcrud
POST/wallethero-api/segments/test-filtersfilters
POST/wallethero-api/segments/union/client-idsfilters
GET/wallethero-api/passes/custom-fieldsfilters
GET/wallethero-api/passes/custom-fields/:fieldName/valuesfilters

SDK Example

typescript
import { WalletHero } from "@wallethero/sdk";
const wh = new WalletHero({ apiToken: "YOUR_TOKEN" });

const { data: segment } = await wh.segments.create({
  workspace_id: "WORKSPACE_ID",
  name: "High Value VIPs",
  filters: [
    {
      filter_type: "custom_field",
      filter_config: {
        custom_field_filters: {
          tier: { operator: "_in", value: ["Gold", "Platinum"] },
        },
      },
    },
  ],
});

const size = await wh.segments.calculateSize(segment.id);
console.log(`Segment has ${size.total} clients`);

WalletHero Documentation