---
title: "Create a Rule"
method: POST
path: "/streaming/v2/rules"
tags: ["rule"]
---

# Create a Rule

`POST /streaming/v2/rules`

Creates a new rule. Duplicate rules are not allowed.

## Request body

- NewRule
  - `name` string, required — The name of the rule
  - `description` string — Optional description of the rule
  - `protocol` string, required — Protocol the rule applies to
  - `network` string, required — Network context of the rule
  - `type` string, required — The rule type
  - `isActive` boolean — Whether the rule is active or not
  - `safeDistance` integer — Safety distance parameter
  - `safeTimeout` integer — Safety timeout parameter
  - `condition_type` 'antlr' | 'match_var', required — Type of condition syntax used
  - `condition` union, required — Condition expressions for the rule
    - MatchVar[] — A list of variables used in a matching rule. Each item in the array must reference a valid MatchVar object.
      - `variable_type` string, required
      - `variable_id` string, uuid, required
    - string — A rule expression to define filtering or matching logic. For example, `height > 0` filters out items where the height is not greater than zero.
  - `target` string, uuid, required — ID of the target associated with the rule
  - `template` union
    - string, uuid — An ID representing a specific template.
    - 'UNIFIED_V1' | 'UNIFIED_V1_RAW' | 'ALL_DATA' | 'INPUT_EMAIL' | 'OUTPUT_EMAIL' | 'TX_EMAIL' — Available predefined templates that can be used for event formatting

## Response `201`

Rule created

- Rule
  - `id` string, uuid
  - `name` string, required
  - `description` string
  - `protocol` string, required
  - `network` string, required
  - `type` string, required
  - `isActive` boolean
  - `safeDistance` integer
  - `safeTimeout` integer
  - `condition_type` 'antlr' | 'match_var', required
  - `condition` union, required
    - MatchVar[] — A list of variables used in a matching rule. Each item in the array must reference a valid MatchVar object.
      - `variable_type` string, required
      - `variable_id` string, uuid, required
    - string — A rule expression to define filtering or matching logic. For example, `height > 0` filters out items where the height is not greater than zero.
  - `target` string, uuid, required
  - `template` union
    - string, uuid — An ID representing a specific template.
    - 'UNIFIED_V1' | 'UNIFIED_V1_RAW' | 'ALL_DATA' | 'INPUT_EMAIL' | 'OUTPUT_EMAIL' | 'TX_EMAIL' — Available predefined templates that can be used for event formatting
  - `created_at` string, date-time
  - `updated_at` string, date-time

## Other responses

- `default` — Unexpected error

---

[API](https://skmtc.dev/blockdaemon/apis/staking-api.md) · [All operations](https://skmtc.dev/blockdaemon/apis/staking-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/blockdaemon/staking-api/revisions/f94e296a08a3/schema)
