{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/sendgrid/main/json-schema/sendgrid-contactdb-segments-schema.json",
  "title": "Create a Segment request",
  "x-generated": "2026-10-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/sendgrid-segments-api-openapi.yml#/components/schemas/ContactdbSegments",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "The name of this segment."
    },
    "list_id": {
      "type": "integer",
      "description": "The list id from which to make this segment. Not including this ID will mean your segment is created from the main contactdb rather than a list."
    },
    "conditions": {
      "type": "array",
      "description": "The conditions for a recipient to be included in this segment.",
      "items": {
        "$ref": "#/$defs/ContactdbSegmentsConditions"
      }
    },
    "recipient_count": {
      "type": "number",
      "description": "The count of recipients in this list. This is not included on creation of segments."
    }
  },
  "required": [
    "name",
    "conditions"
  ],
  "$defs": {
    "AndOr": {
      "type": "string",
      "enum": [
        "and",
        "or",
        ""
      ]
    },
    "ContactdbSegmentsConditions": {
      "title": "ContactDB: Segments: Conditions",
      "type": "object",
      "properties": {
        "field": {
          "type": "string"
        },
        "value": {
          "type": "string"
        },
        "operator": {
          "type": "string",
          "$ref": "#/$defs/Operator"
        },
        "and_or": {
          "type": "string",
          "$ref": "#/$defs/AndOr"
        }
      },
      "required": [
        "field",
        "value",
        "operator"
      ]
    },
    "Operator": {
      "type": "string",
      "enum": [
        "eq",
        "ne",
        "lt",
        "gt",
        "contains"
      ]
    }
  }
}