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

# Add a custom rule

> Add an organization-level restricted-goods rule.

Requires the `restrict:read` scope.

A rule must have at least one of `hs_prefix`, `keywords`, or
`origin_countries` — a rule that could match nothing is rejected with `400`.

<ParamField body="rule_type" type="string" required>
  `prohibition`, `restriction`, or `observation`.
</ParamField>

<ParamField body="title" type="string" required>
  Short rule name (up to 200 chars) — shown on matches.
</ParamField>

<ParamField body="country" type="string" default="*">
  Imposing country (ISO alpha-2), or `*` for any destination (import
  rules) / any origin leg (export rules).
</ParamField>

<ParamField body="measure_direction" type="string" default="import">
  `import` (checked against the ship-to country) or `export` (checked
  against the ship-from country).
</ParamField>

<ParamField body="hs_prefix" type="string">
  HS code prefix (up to 14 chars; non-digits are stripped, stored to 10
  digits). Items whose code falls under this prefix match.
</ParamField>

<ParamField body="keywords" type="array">
  Up to 100 keywords (each 1–100 chars, lower-cased on storage). Matched
  against the item's title/description/materials/category/brand text.
</ParamField>

<ParamField body="origin_countries" type="array">
  Up to 300 ISO alpha-2 codes — the rule fires on items manufactured in
  any of them.
</ParamField>

<ParamField body="summary" type="string">
  Longer explanation (up to 10000 chars) returned on matches.
</ParamField>

<ResponseField name="rule" type="object | null">
  `{ id }` of the created rule.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://{partner}.mytraddal.com/admin/api/v1/restrict/rules \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer {access_token}' \
    -d '{
      "rule_type": "prohibition",
      "title": "No standalone lithium batteries",
      "keywords": ["lithium battery", "power bank"],
      "summary": "Company policy: we do not ship standalone lithium batteries on any lane."
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "success": true,
    "message": "Rule added",
    "rule": { "id": 7 }
  }
  ```
</ResponseExample>
