{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/groundmail-dev/json-schema/groundmail-dev-create-automation-request-schema.json",
  "title": "CreateAutomationRequest",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/groundmail-dev-automations-api-openapi.yml#/components/schemas/CreateAutomationRequest",
  "type": "object",
  "required": [
    "name",
    "trigger",
    "steps"
  ],
  "properties": {
    "name": {
      "type": "string"
    },
    "trigger": {
      "$ref": "#/$defs/AutomationTrigger"
    },
    "steps": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AutomationStep"
      },
      "minItems": 1,
      "maxItems": 20
    },
    "folder": {
      "type": "string",
      "maxLength": 64,
      "description": "Folder to file it in on the dashboard, matched by name (any case) and created when it does not exist."
    }
  },
  "$defs": {
    "AutomationStep": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "delay",
            "send_email",
            "send_sms",
            "condition",
            "wait_for_event"
          ]
        }
      },
      "additionalProperties": true,
      "description": "Step object. Shape depends on `type`:\n- `delay`: `{ type, seconds }`\n- `send_email`: `{ type, email: { from, to, subject?, html?, text?, template?, category? } }`. `category` is `transactional` or `product` (`newsletter` is rejected); when omitted the step sends as its template's category, else `transactional`. Merge fields accept a default: `{{event.data.name | default:\"there\"}}`. Values merged into `html` are HTML-escaped, and `{{unsubscribe_url}}` is filled in with the managed unsubscribe link.\n- `send_sms`: `{ type, sms: { to, body, from?, messaging_service_sid? } }` (requires Twilio integration)\n- `condition`: `{ type, path, operator, value? }` (false stops the run)\n- `wait_for_event`: `{ type, event, timeout_seconds?, on_timeout? }` (`on_timeout` is `continue` or `fail`, default `fail`)\n"
    },
    "AutomationTrigger": {
      "type": "object",
      "required": [
        "type",
        "event"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "event"
          ]
        },
        "event": {
          "type": "string"
        },
        "cancel_on_events": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "maxItems": 20,
          "description": "When any listed event fires for the same recipient, cancel queued/running/waiting runs for this automation."
        },
        "once_per_contact": {
          "type": "boolean",
          "description": "Enrol each recipient at most once, ever. Matched on the trigger event's `email` or `user_id`. A later matching event is reported in `enrollment_skips` instead of starting a run."
        },
        "cooldown_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3650,
          "description": "Do not enrol the same recipient again within this many days of their last run on this automation. Ignored when `once_per_contact` is true."
        }
      }
    }
  }
}