## CC rules (`cc-rules`)

Ordered combinations of matchers and filters; a site can pick one rule group.

Authentication: User (some parameters admin only) · Docs: https://www-demo.kuxitong.com/en/docs/api/cc-rules

### GET `/api/v2/cc-rules`

List CC rule groups · Authentication: User (some parameters admin only)

Query parameters:

| Field | Type | Required | Description |
|---|---|---|---|
| `page` | integer |  | Page number, starting from 1 Default: 1 |
| `page_size` | integer |  | Items per page Default: 20 |
| `sort` | string |  | Sort fields, comma-separated; prefix `-` for descending, e.g. `-created_at,id` |
| `tenant_id` | integer |  | Admin only: filter by tenant. Ignored for tenant credentials, which only see their own tenant's data |
| `enabled` | boolean |  | Filter by enabled state. |
| `name` | string |  | Filter by name substring. |
| `owner` | string |  | platform = platform objects only; tenant = tenant objects only. Values: ["platform","tenant"] |

```sh
curl "https://panel.example.com/api/v2/cc-rules" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### POST `/api/v2/cc-rules`

Create CC rule group · Authentication: User (some parameters admin only)

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `des` | string |  | Remark; empty if omitted (omitting it on update also clears it, since the update replaces the whole object). |
| `enabled` | boolean |  | Whether enabled Default: true |
| `items` | CcRuleItem[] | Yes | Rule items, executed in order; the count is limited by the setting protect.cc_rule_items_max. |
| `name` | string | Yes | Name |
| `show_to` | integer[] |  | Tenants that can see a platform rule group; empty = visible to all tenants, otherwise only the listed tenants can see it and select it as a site's cc_level. Returned to admins only. |
| `sort` | integer |  | Panel sort order (smaller first). |
| `tenant_id` | integer |  | Owning tenant; null = platform object (built-in or created by an admin, read-only for tenants). |
| `visible` | boolean |  | Shown in the site's rule group drop-down. Default: true |

```sh
curl -X POST "https://panel.example.com/api/v2/cc-rules" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"items":[{"action":"ban","filter_ids":[8],"match_id":3}],"name":"js"}'
```

### POST `/api/v2/cc-rules/batch-enable`

Batch enable or disable CC rule groups · Authentication: User (some parameters admin only)

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `enabled` | boolean | Yes | Whether enabled Default: true |
| `ids` | integer[] | Yes | IDs of the objects to change, at most 100. |

```sh
curl -X POST "https://panel.example.com/api/v2/cc-rules/batch-enable" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled":false,"ids":[1,2]}'
```

### GET `/api/v2/cc-rules/{id}`

Get CC rule group · Authentication: User (some parameters admin only)

```sh
curl "https://panel.example.com/api/v2/cc-rules/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### PUT `/api/v2/cc-rules/{id}`

Update CC rule group · Authentication: User (some parameters admin only)

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `des` | string |  | Remark; empty if omitted (omitting it on update also clears it, since the update replaces the whole object). |
| `enabled` | boolean |  | Whether enabled Default: true |
| `items` | CcRuleItem[] | Yes | Rule items, executed in order; the count is limited by the setting protect.cc_rule_items_max. |
| `name` | string | Yes | Name |
| `show_to` | integer[] |  | Tenants that can see a platform rule group; empty = visible to all tenants, otherwise only the listed tenants can see it and select it as a site's cc_level. Returned to admins only. |
| `sort` | integer |  | Panel sort order (smaller first). |
| `tenant_id` | integer |  | Owning tenant; null = platform object (built-in or created by an admin, read-only for tenants). |
| `visible` | boolean |  | Shown in the site's rule group drop-down. Default: true |

```sh
curl -X PUT "https://panel.example.com/api/v2/cc-rules/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"items":[{"action":"ban","filter_ids":[8],"match_id":3}],"name":"js"}'
```

### DELETE `/api/v2/cc-rules/{id}`

Delete CC rule group · Authentication: User (some parameters admin only)

```sh
curl -X DELETE "https://panel.example.com/api/v2/cc-rules/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

CC rules object:

| Field | Type | Required | Description |
|---|---|---|---|
| `builtin` | boolean |  | Built-in object; cannot be deleted. (read-only) |
| `created_at` | string |  | Created at (read-only) |
| `des` | string |  | Remark; empty if omitted (omitting it on update also clears it, since the update replaces the whole object). |
| `enabled` | boolean |  | Whether enabled Default: true |
| `errors` | FieldError[] |  | Why each remaining item was not changed; field is /ids/<index>, code as in the single-item update (not_found, readonly and so on). |
| `id` | integer |  | Record ID (read-only) |
| `ids` | integer[] | Yes | IDs of the objects to change, at most 100. |
| `items` | CcRuleItem[] |  | Rule items, executed in order; the count is limited by the setting protect.cc_rule_items_max. |
| `name` | string |  | Name |
| `ruleset_id` | string |  | Compiled ruleset id: cc.level.<name> for platform groups (referenced by the site's cc_level and guard.default_cc_level); cc.user.r<id> for tenant groups (selectable as cc_level by the tenant's own sites; sites on a package need custom_cc_rule). (read-only) |
| `show_to` | integer[] |  | Tenants that can see a platform rule group; empty = visible to all tenants, otherwise only the listed tenants can see it and select it as a site's cc_level. Returned to admins only. |
| `sort` | integer |  | Panel sort order (smaller first). |
| `tenant_id` | integer |  | Owning tenant; null = platform object (built-in or created by an admin, read-only for tenants). (read-only) |
| `updated` | integer[] |  | IDs that were set (including those already in the target state), in request order. |
| `updated_at` | string |  | Updated at (read-only) |
| `visible` | boolean |  | Shown in the site's rule group drop-down. Default: true |
