{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/sendly-now/json-schema/sendly-now-segment-v1-schema.json",
  "title": "SegmentV1",
  "description": "A segment as exposed on the v1 API.",
  "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/SegmentV1",
  "properties": {
    "condition": {
      "anyOf": [
        {
          "$ref": "#/$defs/FilterConditionV1"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {
      "format": "date-time",
      "type": "string"
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "id": {
      "format": "uuid",
      "type": "string"
    },
    "member_count": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "track_membership": {
      "type": "boolean"
    },
    "type": {
      "enum": [
        "DYNAMIC",
        "STATIC"
      ],
      "type": "string"
    },
    "updated_at": {
      "format": "date-time",
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "description",
    "type",
    "condition",
    "track_membership",
    "member_count",
    "created_at",
    "updated_at"
  ],
  "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"
    }
  }
}