---
title: "Replace a code's smart rules"
method: PUT
path: "/api/v1/codes/{id}/smart-rules"
tags: ["smart-links"]
---

# Replace a code's smart rules

`PUT /api/v1/codes/{id}/smart-rules`

## Request

- Base URL: `https://app.qrtap.kg`
- URL: `https://app.qrtap.kg/api/v1/codes/{id}/smart-rules`
- Auth: HTTP bearer

Replaces the code's rule set (max 5 rules). On every scan the rules are evaluated in order and the FIRST match wins; if nothing matches — or the stored set is ever unreadable — the redirect falls back to the code's primary destination, so a bad rule can never break a printed code. `rules: []` or `rules: null` clears the set.

Conditions: `{"kind":"device","in":["ios","android","desktop","other"]}`, `{"kind":"lang","in":["ru","ky"]}`, `{"kind":"hours","tz":"Asia/Bishkek","from":"09:00","to":"18:00","days":[1,2,3,4,5]}` (`to` exclusive; from > to crosses midnight; days are ISO 1=Mon..7=Sun). Evaluation uses coarse classified signals only — raw IP, user-agent and Accept-Language are never stored. Smart rules require a paid plan (402 otherwise).

## Path parameters

- `id` string, uuid, required

## Request body

- SmartRulesRequest
  - `rules` SmartRule[], nullable, required: The full rule array (replaces whatever was stored). `[]` or `null` clears the rules.
    - `if` union, required: Evaluated against coarse, already-classified request signals only — never a raw IP, user-agent or Accept-Language header.
      - object
        - `kind` 'device', required
        - `in` string[], required
      - object
        - `kind` 'lang', required
        - `in` string[], required: Primary language subtags, e.g. ["ru","ky"].
      - object
        - `kind` 'hours', required
        - `tz` string, required: IANA timezone, e.g. Asia/Bishkek.
        - `from` string, required
        - `to` string, required: Exclusive. A window where from > to crosses midnight.
        - `days` integer[]: ISO weekdays, 1 = Monday … 7 = Sunday. Omit for every day.
    - `to` string, uri, required: Destination for this rule (http/https).

## Response `200`

The stored (normalised) rule set.

- SmartRulesResponse
  - `code_id` string, uuid, required
  - `version` 1, required: Rule-set schema version (currently always 1).
  - `rules` SmartRule[], required
    - `if` union, required: Evaluated against coarse, already-classified request signals only — never a raw IP, user-agent or Accept-Language header.
      - object
        - `kind` 'device', required
        - `in` string[], required
      - object
        - `kind` 'lang', required
        - `in` string[], required: Primary language subtags, e.g. ["ru","ky"].
      - object
        - `kind` 'hours', required
        - `tz` string, required: IANA timezone, e.g. Asia/Bishkek.
        - `from` string, required
        - `to` string, required: Exclusive. A window where from > to crosses midnight.
        - `days` integer[]: ISO weekdays, 1 = Monday … 7 = Sunday. Omit for every day.
    - `to` string, uri, required: Destination for this rule (http/https).

## Other responses

- `400`: Body is not `{"rules": […] | null}` (`invalid_request`), the id is not a UUID (`invalid_id`), or a rule target is not an http(s) URL (`invalid_url`).
- `401`: Missing, invalid or revoked API key.
- `402`: The capability exists but the workspace plan does not open it (bulk creation, scan webhooks, writing smart rules). Deliberately 402 and not 403: the request is valid and the identical call succeeds once the plan is upgraded — nothing in the integration has to change. Does not spend daily quota.
- `404`: No such object in your organization.
- `422`: A rule is structurally invalid (unknown condition kind, bad time, unknown timezone, more than 5 rules …).
- `429`: Limit exceeded — the request had no effect. `error` is `rate_limited` with `scope: "minute"` (a burst brake: wait `retry_after` seconds and continue) or `quota_exceeded` with `scope: "day"` (the workspace's daily quota, counted in UTC; it returns at `reset_at`, the next UTC midnight, and only a higher plan raises it before then).

---

[API](https://skmtc.dev/qrtap/apis/qrtap-rest-api.md) · [All operations](https://skmtc.dev/qrtap/apis/qrtap-rest-api/llms.txt) · [OpenAPI document](https://skmtc.dev/qrtap/apis/qrtap-rest-api/revisions/8af17ac525bd?raw)
