> ## Documentation Index
> Fetch the complete documentation index at: https://docs-attestly.code4source.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rulesets catalog

> Save, list, and inspect rulesets.

The catalog stores rulesets so you can reference them by `name@version`
on `/v1/evaluate` instead of sending the body inline every time.

## Endpoints

| Method | Path                            | Purpose                         |
| ------ | ------------------------------- | ------------------------------- |
| POST   | `/v1/rulesets`                  | Create a new `(name, version)`. |
| GET    | `/v1/rulesets`                  | List rulesets (paginated).      |
| GET    | `/v1/rulesets/{name}`           | Get the latest version.         |
| GET    | `/v1/rulesets/{name}/{version}` | Get a specific version.         |

## Create

```bash theme={null}
curl -X POST https://api-attestly.code4source.com/v1/rulesets \
  -H "Authorization: Bearer atk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "br-rural-credit",
    "version": 1,
    "sets":   { ... },
    "checks": [ ... ]
  }'
```

`version` is an integer. Omit it to let the API assign the next free
version. `(name, version)` pairs are immutable — re-`POST`ing the same
pair returns `409 RULESET_ALREADY_EXISTS`.

### Response

```json theme={null}
{
  "data": {
    "ruleset": "br-rural-credit",
    "version": 1,
    "body": { ... },
    "body_hash": "8a3c...",
    "created_at": "2026-05-05T12:00:00Z",
    "created_by": "org_01HX...",
    "display_name": null,
    "description": null,
    "tags": [],
    "resolved_colors": {
      "ruleset": "#3b82f6",
      "checks": { "no_indigenous_overlap": "#dc2626" },
      "outcomes": {
        "compliant": "#16a34a",
        "warning": "#f59e0b",
        "non_compliant": "#dc2626",
        "degraded": "#6b7280"
      }
    }
  }
}
```

## List

```bash theme={null}
GET /v1/rulesets?page=1&page_size=25
GET /v1/rulesets?tag=preset
GET /v1/rulesets?tag=preset&tag=brazil
```

| Query param | Notes                                                                                  |
| ----------- | -------------------------------------------------------------------------------------- |
| `page`      | 1-indexed. Defaults to `1`.                                                            |
| `page_size` | Items per page. Defaults to `25`, max `200`.                                           |
| `tag`       | Repeat to require multiple tags (AND). Use `tag=preset` for curated official rulesets. |

Returns a paginated metadata listing:

```json theme={null}
{
  "data": {
    "items": [
      {
        "ruleset": "br-rural-credit",
        "version": 1,
        "body_hash": "8a3c...",
        "created_at": "2026-05-05T12:00:00Z",
        "created_by": "org_01HX...",
        "display_name": null,
        "description": null,
        "tags": [],
        "color": "#3b82f6"
      }
    ],
    "pagination": { "page": 1, "page_size": 25, "total_count": 42, "total_pages": 2 }
  }
}
```

## Get

```bash theme={null}
GET /v1/rulesets/br-rural-credit          # latest version
GET /v1/rulesets/br-rural-credit/1        # pinned version
```

Both return the same shape as the `POST` response above.
