{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/scrip-dev/json-schema/scrip-dev-event-detail-response-schema.json",
  "title": "EventDetailResponse",
  "description": "An event with its processing status and the rule evaluations it produced.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/scrip-dev-openapi.json#/components/schemas/EventDetailResponse",
  "properties": {
    "created_at": {
      "description": "When this event was created",
      "format": "date-time",
      "type": "string"
    },
    "error_code": {
      "description": "Why a FAILED event failed, as a code from the Errors page, such as `program_inactive`, `participant_inactive` or `unknown_participant`. Absent when the event did not fail or the failure has no code.",
      "type": "string"
    },
    "error_message": {
      "description": "Error details if the event failed during processing",
      "type": "string"
    },
    "event_data": {
      "description": "Original event data payload",
      "type": "object"
    },
    "event_timestamp": {
      "description": "When the event occurred (from the ingestion request)",
      "format": "date-time",
      "type": "string"
    },
    "event_type": {
      "description": "The name you gave the event, such as `purchase`. Rules read it as `event.type`. Absent for an event stored before events had a name.",
      "type": "string"
    },
    "external_id": {
      "description": "Your system's identifier for the participant (the value provided at ingestion)",
      "type": "string"
    },
    "first_error_code": {
      "description": "The event's cause: the first error_code it failed with. GET /v1/reports/failure-causes groups events by it, and GET /v1/events can filter by it. The event keeps it after a retry. Absent when the event never failed with a code.",
      "type": "string"
    },
    "first_failed_at": {
      "description": "When the event first failed (RFC 3339). The event keeps it after a retry; its latest failure is processed_at. Absent when the event never failed.",
      "format": "date-time",
      "type": "string"
    },
    "id": {
      "description": "Unique identifier for this event",
      "format": "uuid",
      "type": "string"
    },
    "idempotency_key": {
      "description": "Client-provided unique key for deduplication",
      "type": "string"
    },
    "participant_id": {
      "description": "Participant UUID, resolved from external_id if one was provided at ingestion",
      "format": "uuid",
      "type": "string"
    },
    "processed_at": {
      "description": "When the event finished processing (null while pending or processing)",
      "format": "date-time",
      "type": "string"
    },
    "program_id": {
      "description": "Program this event belongs to",
      "format": "uuid",
      "type": "string"
    },
    "received_at": {
      "description": "When Scrip received the event",
      "format": "date-time",
      "type": "string"
    },
    "recipient_id": {
      "description": "Recipient participant UUID sent as recipient_id or recipient_external_id; rules read it as recipient.id",
      "format": "uuid",
      "type": "string"
    },
    "reversal": {
      "$ref": "#/$defs/EventReversalSummary",
      "description": "Whether the rewards this event issued were later reversed."
    },
    "reversals": {
      "description": "Up to 100 most recent reversals of the event's rewards, newest first (returned with `expand[]=reversals`).",
      "items": {
        "$ref": "#/$defs/EventReversalRecord"
      },
      "type": "array"
    },
    "rule_evaluations": {
      "description": "Recorded rule evaluations for this event (`SKIPPED_ERROR` and `SKIPPED_TIMEOUT` are omitted unless `include_skipped=true`; false conditions and rules after `stop_after_match` are not recorded).",
      "items": {
        "$ref": "#/$defs/RuleEvaluationResponse"
      },
      "type": "array"
    },
    "source": {
      "description": "Whether you sent the event or Scrip generated it.",
      "enum": [
        "EXTERNAL",
        "SYSTEM",
        "OPERATIONAL"
      ],
      "type": "string"
    },
    "status": {
      "description": "Where the event is in processing.",
      "enum": [
        "PENDING",
        "PROCESSING",
        "COMPLETED",
        "FAILED"
      ],
      "type": "string"
    },
    "updated_at": {
      "description": "When this event was last updated",
      "format": "date-time",
      "type": "string"
    }
  },
  "type": "object",
  "$defs": {
    "ActorResponse": {
      "description": "Who caused an audited change: a dashboard user, an API key, a rule, Scrip itself, or a subject that a trusted integration asserted.",
      "properties": {
        "actor_source": {
          "description": "How the change was made.",
          "enum": [
            "DIRECT_USER",
            "DIRECT_API_KEY",
            "RULE",
            "SYSTEM",
            "ASSERTED"
          ],
          "type": "string"
        },
        "api_key_id": {
          "description": "API key that made the change; present for DIRECT_API_KEY.",
          "format": "uuid",
          "type": "string"
        },
        "external_subject": {
          "description": "Subject identifier the integration asserted; present for ASSERTED.",
          "type": "string"
        },
        "external_subject_type": {
          "description": "What kind of identifier `external_subject` is; present for ASSERTED.",
          "enum": [
            "OAUTH_SUBJECT",
            "EMAIL"
          ],
          "type": "string"
        },
        "rule_id": {
          "description": "Rule whose action made the change; present for RULE.",
          "format": "uuid",
          "type": "string"
        },
        "user_id": {
          "description": "Dashboard user who made the change; present for DIRECT_USER.",
          "format": "uuid",
          "type": "string"
        },
        "via_api_key_id": {
          "description": "API key the asserting integration used; present for ASSERTED.",
          "format": "uuid",
          "type": "string"
        }
      },
      "type": "object"
    },
    "EventReversalLineResponse": {
      "description": "How much of one original award a reversal asked for, recovered and could not recover.",
      "properties": {
        "asset_id": {
          "description": "Asset of the award",
          "format": "uuid",
          "type": "string"
        },
        "ledger_entity_id": {
          "description": "Ledger entity that was originally credited",
          "format": "uuid",
          "type": "string"
        },
        "original_amount": {
          "description": "Amount the original award credited",
          "type": "string"
        },
        "original_journal_entry_id": {
          "description": "Journal entry of the original award",
          "format": "uuid",
          "type": "string"
        },
        "recovered_amount": {
          "description": "Amount actually recovered from value still traceable to the original award",
          "type": "string"
        },
        "requested_amount": {
          "description": "Amount this reversal asked to claw back from this line",
          "type": "string"
        },
        "reversal_journal_entry_id": {
          "description": "REVERSAL journal entry that debited the recovered value; absent when nothing was recovered",
          "format": "uuid",
          "type": "string"
        },
        "shortfall_amount": {
          "description": "Requested value that could not be recovered (spent, expired, transferred, or held)",
          "type": "string"
        }
      },
      "type": "object"
    },
    "EventReversalRecord": {
      "description": "One reversal of an event's rewards: when and why it was made, who made it, and what each original award gave back.",
      "properties": {
        "actor": {
          "$ref": "#/$defs/ActorResponse",
          "description": "Who made the reversal. Absent only on some older reversals that recovered nothing."
        },
        "created_at": {
          "description": "When the reversal was made (RFC 3339).",
          "format": "date-time",
          "type": "string"
        },
        "event_id": {
          "description": "The event whose rewards were reversed.",
          "format": "uuid",
          "type": "string"
        },
        "fraction": {
          "description": "The fraction of each award the request reversed, such as `0.5`. Absent when the request reversed all remaining value.",
          "type": "string"
        },
        "id": {
          "description": "Unique identifier for this reversal.",
          "format": "uuid",
          "type": "string"
        },
        "idempotency_key": {
          "description": "The key sent with the reversal request.",
          "type": "string"
        },
        "lines": {
          "description": "For each original award, the amount requested, recovered and not recovered.",
          "items": {
            "$ref": "#/$defs/EventReversalLineResponse"
          },
          "type": "array"
        },
        "reason": {
          "description": "Why the event was reversed, as sent with the request.",
          "type": "string"
        },
        "shortfall_policy": {
          "description": "What Scrip did with value it could not recover.",
          "enum": [
            "report"
          ],
          "type": "string"
        },
        "status": {
          "description": "The outcome of the reversal.",
          "enum": [
            "COMPLETED"
          ],
          "type": "string"
        }
      },
      "type": "object"
    },
    "EventReversalSummary": {
      "description": "Whether the rewards an event issued were reversed, and when. Read each reversal with GET /v1/events/{event_id}?expand[]=reversals.",
      "properties": {
        "last_reversed_at": {
          "description": "When the latest reversal was made (RFC 3339). Absent when status is NONE.",
          "format": "date-time",
          "type": "string"
        },
        "status": {
          "description": "Reversal state: `NONE` (not reversed), `PARTIAL` (partially reversed), or `FULL` (all reversible awards recovered).",
          "enum": [
            "NONE",
            "PARTIAL",
            "FULL"
          ],
          "type": "string"
        }
      },
      "type": "object"
    },
    "RuleEvaluationResponse": {
      "description": "The outcome of one rule for one event, and why.",
      "properties": {
        "created_at": {
          "description": "When the evaluation occurred",
          "format": "date-time",
          "type": "string"
        },
        "error_message": {
          "description": "Details of a failure or skip (e.g. budget usage and reset time for `PARTICIPANT_BUDGET_EXCEEDED`, or the conflicting key for `SHARED_STATE_CHANGED`).",
          "type": "string"
        },
        "id": {
          "description": "Unique identifier for this evaluation record",
          "format": "uuid",
          "type": "string"
        },
        "reason": {
          "description": "Skip classification for `SKIPPED` evaluations (`OUTSIDE_TIME_WINDOW`, `BUDGET_EXCEEDED`, `PARTICIPANT_BUDGET_EXCEEDED`, or `SHARED_STATE_CHANGED`), or `REFERENCE_ALREADY_SETTLED` on a `SUCCESS` evaluation. Absent otherwise.",
          "type": "string"
        },
        "rule_history_id": {
          "description": "Snapshot of the rule version that was active when this evaluation occurred",
          "format": "uuid",
          "type": "string"
        },
        "rule_id": {
          "description": "Rule that was evaluated",
          "format": "uuid",
          "type": "string"
        },
        "rule_name": {
          "description": "The name of the rule when it was evaluated.",
          "type": "string"
        },
        "rule_set_id": {
          "description": "Rule set that contained the rule when this evaluation occurred",
          "format": "uuid",
          "type": "string"
        },
        "status": {
          "description": "The recorded result of the evaluation.",
          "enum": [
            "SUCCESS",
            "FAILED",
            "SKIPPED",
            "SKIPPED_ERROR",
            "SKIPPED_TIMEOUT"
          ],
          "type": "string"
        },
        "stopped_by_rule_id": {
          "description": "Earlier rule whose `stop_after_match` skipped this rule (present only in rule configuration simulations).",
          "format": "uuid",
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}