---
title: "Create custom rule"
method: POST
path: "/api/v2/rules/create"
tags: ["Rules"]
---

# Create custom rule

`POST /api/v2/rules/create`

## Request

- Base URL: `https://zeropath.com`
- URL: `https://zeropath.com/api/v2/rules/create`
- Auth: API key in header `X-ZeroPath-API-Token-Id` and API key in header `X-ZeroPath-API-Token-Secret`

Create a natural language security rule. Only `name` and `rule` are required — all other fields are optional. Rules apply org-wide by default. Pass `repositoryIds` to restrict the rule to specific repos, or pass `tagIds` without `repositoryIds` to scope the rule to repositories carrying those tags. Use `allRepositories: true` when you want org-wide scope while also associating tags.

## Request body

- CreateRuleInput
  - `organizationId` string
  - `name` string, required: Name for the custom rule
  - `rule` string, required: Natural language description of the security rule
  - `globPattern` string: Glob pattern for files this rule applies to
  - `sourceTypes` string[]: Source types this rule applies to
  - `repositoryIds` string[]: Optional. Repository IDs to restrict this rule to. When omitted, the rule applies to ALL repositories in the organization. You do not need to look up repositories first.
  - `allRepositories` true: Set to true to make the rule apply to all repositories, including when tagIds are also supplied.
  - `scope` 'allRepositories' | 'repositories' | 'tags': Optional explicit scope. Use tags with tagIds to apply the rule only to repositories carrying those tags.
  - `tagIds` string[]: Optional. Tag IDs to scope or associate with this rule. On create, tagIds without repositoryIds/allRepositories create a tag-scoped rule.

## Response `200`

Rule created successfully

- Rule
  - `id` string, required
  - `name` string, required
  - `rule` string, required: Natural language description of the security rule
  - `globPattern` string, required
  - `sourceTypes` string[], required
  - `source` 'USER' | 'SECURITY_COMPASS'
  - `repositoryIds` string[], required
  - `scope` 'allRepositories' | 'repositories' | 'tags', required
  - `tags` RuleTag[], required
    - `id` string, required
    - `name` string, required
  - `createdAt` string, date-time, required
  - `updatedAt` string, date-time, required

## Other responses

- `400`: Error Response
- `401`: Error Response

---

[API](https://skmtc.dev/zeropath/apis/zeropath-api.md) - [All operations](https://skmtc.dev/zeropath/apis/zeropath-api/llms.txt) - [OpenAPI document](https://skmtc.dev/zeropath/apis/zeropath-api/revisions/126e9c80ba0d?raw)
