{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/sendly-now/json-schema/sendly-now-segment-v1-create-schema.json",
  "title": "SegmentV1Create",
  "description": "Body for POST /api/v1/segments. `condition` is required when `type` is `DYNAMIC`.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/sendly-now-segments-api-openapi.yml#/components/schemas/SegmentV1Create",
  "properties": {
    "condition": {
      "$ref": "#/$defs/FilterConditionV1"
    },
    "description": {
      "maxLength": 500,
      "type": "string"
    },
    "name": {
      "maxLength": 100,
      "minLength": 1,
      "type": "string"
    },
    "track_membership": {
      "default": false,
      "description": "Emit segment entry/exit events as contacts move in and out. Off by default — it costs a membership write per transition.",
      "type": "boolean"
    },
    "type": {
      "default": "DYNAMIC",
      "enum": [
        "DYNAMIC",
        "STATIC"
      ],
      "type": "string"
    }
  },
  "required": [
    "name"
  ],
  "type": "object",
  "$defs": {
    "FilterConditionV1": {
      "description": "A filter condition: one or more groups combined with `logic`.",
      "properties": {
        "groups": {
          "items": {
            "$ref": "#/$defs/FilterGroupV1"
          },
          "minItems": 1,
          "type": "array"
        },
        "logic": {
          "enum": [
            "AND",
            "OR"
          ],
          "type": "string"
        }
      },
      "required": [
        "logic",
        "groups"
      ],
      "type": "object"
    },
    "FilterGroupV1": {
      "description": "A group of filters. The filters inside one group ALWAYS combine with AND; `conditions` nests a further condition under this group, which is how OR-of-ANDs (and deeper) is expressed.",
      "properties": {
        "conditions": {
          "$ref": "#/$defs/FilterConditionV1"
        },
        "filters": {
          "items": {
            "$ref": "#/$defs/SegmentFilterV1"
          },
          "type": "array"
        }
      },
      "required": [
        "filters"
      ],
      "type": "object"
    },
    "SegmentFilterV1": {
      "description": "One comparison. `field` addresses a contact column (`email`, `subscribed`, `createdAt`, `updatedAt`), a `customFields.<key>` path, an `event.<name>`, an `email.<activity>` or `segment`; any other field is refused with 400. A list is not a field — a campaign targets one with `audience_type: \"LIST\"` and `list_id`. `value` is whatever the operator compares against — its JSON type follows the field, and it is omitted entirely for the presence operators (`exists`, `notExists`). `unit` applies only to the relative-time operators (`within`, `olderThan`, and the `triggered*` family).",
      "properties": {
        "field": {
          "minLength": 1,
          "type": "string"
        },
        "operator": {
          "enum": [
            "equals",
            "notEquals",
            "contains",
            "notContains",
            "greaterThan",
            "lessThan",
            "greaterThanOrEqual",
            "lessThanOrEqual",
            "exists",
            "notExists",
            "within",
            "olderThan",
            "triggered",
            "triggeredWithin",
            "triggeredOlderThan",
            "notTriggered",
            "notTriggeredWithin",
            "isMemberOf"
          ],
          "type": "string"
        },
        "unit": {
          "enum": [
            "days",
            "hours",
            "minutes"
          ],
          "type": "string"
        },
        "value": {}
      },
      "required": [
        "field",
        "operator"
      ],
      "type": "object"
    }
  }
}