> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sendrealm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Automation Reliability

> Validate definitions, control failed runs, and test waits without delivery.

## Validate before publish

`POST /automations/validate` accepts `{ "definition": { ... } }` and returns
`valid`, human-readable `errors`, and structured validation `issues`.

`wait_for_event` supports a canonical `timeout_seconds` value. Legacy
`timeout: { amount, unit }` definitions are normalized for compatibility, but
new definitions should always use seconds.

## Correlated waits

Define a trigger correlation key and use the same key on a wait:

```json theme={null}
{
  "trigger": {
    "event_name": "checkout.started",
    "correlation": {
      "key": "checkout_id",
      "duplicate_policy": "ignore_active"
    }
  },
  "steps": [
    {
      "key": "wait_for_checkout",
      "type": "wait_for_event",
      "config": {
        "event_name": "checkout.completed",
        "timeout_seconds": 3600,
        "correlation": { "key": "checkout_id" }
      }
    }
  ]
}
```

Use `end_automation` as a terminal step for an explicit successful branch.

## Run controls

* `POST /automation-runs/:runId/cancel`
* `POST /automation-runs/:runId/retry`

Both accept an optional `{ "reason": "..." }`, are project-scoped and audited,
and require a Sendrealm API key. Cancellation cannot retract a delivery that
has already started.

## Test runs

Test a saved draft without delivery or production mutations:

* `POST /automations/:id/test-runs`
* `GET /automation-test-runs/:runId`
* `POST /automation-test-runs/:runId/events`
* `POST /automation-test-runs/:runId/advance`

Test runs record simulated actions, use isolated synthetic events, and advance
delays or wait timeouts with a virtual clock.


## OpenAPI

````yaml api-reference/openapi.json POST /automations/validate
openapi: 3.0.1
info:
  title: Sendrealm API
  description: >-
    API for email, push, audience resources, domains, campaign drafts,
    templates, events, topics, and automations
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.sendrealm.com
security:
  - bearerAuth: []
paths:
  /automations/validate:
    post:
      summary: Validate an automation definition
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - definition
              properties:
                definition:
                  type: object
                  additionalProperties:
                    $ref: '#/components/schemas/JsonValue'
      responses:
        '200':
          description: Validation result with errors and structured issues
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AutomationValidationResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    JsonValue:
      oneOf:
        - type: string
          nullable: true
        - type: number
        - type: boolean
        - type: object
          additionalProperties:
            $ref: '#/components/schemas/JsonValue'
        - type: array
          items:
            $ref: '#/components/schemas/JsonValue'
    AutomationValidationResponse:
      type: object
      required:
        - status
        - data
      properties:
        status:
          type: integer
          description: HTTP response status code
        data:
          type: object
          required:
            - valid
            - errors
            - issues
          properties:
            valid:
              type: boolean
            errors:
              type: array
              items:
                type: string
            issues:
              type: array
              items:
                $ref: '#/components/schemas/ValidationIssue'
    ValidationIssue:
      type: object
      required:
        - code
        - path
        - message
      properties:
        code:
          type: string
        path:
          type: string
          nullable: true
        message:
          type: string
    Error:
      type: object
      required:
        - status
        - error
      properties:
        status:
          type: integer
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details:
              $ref: '#/components/schemas/JsonValue'
            issues:
              type: array
              items:
                $ref: '#/components/schemas/ValidationIssue'
  responses:
    Unauthorized:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````