# Expected Schema Check API

Source: https://userguide.qualytics.io/data-quality-checks/expected-schema/api/

This page documents how to create and manage an Expected Schema check via the REST API. The check uses the standard Quality Checks endpoints: set `rule` to `expectedSchema` and declare the contract under `properties`. The rule reads the container itself, so `fields` is not used. All endpoints share the base URL of your deployment (for example, `https://your-instance.qualytics.io/api`) and require a Bearer token.

> **Tip**
>
> For complete API documentation, including request and response schemas, visit the [API docs](https://userguide.qualytics.io/api/docs).

> **Note: Permissions**
>
> All endpoints require the **Member** role plus a team permission on the check's datastore: **Reporter** to read, **Author** to create or update an Active check, archive, or delete, and **Drafter** to create or update a Draft. See [Permissions](https://userguide.qualytics.io/data-quality-checks/expected-schema/deep-dive/permissions/) for the full matrix.

## The `properties` object

Expected Schema carries its rule-specific configuration under `properties`:

| Field | Required | Type | Description |
| --- | --- | --- | --- |
| `list` | Yes | `array` | The names of the fields the container must carry. Names only: the type each one is checked against comes from the field's profile, not from this payload. |
| `allow_other_fields` | Yes | `boolean` | `true` tolerates columns outside the declaration; `false` requires the container to hold exactly the declared set. |

## Create

**Endpoint:** `POST /api/quality-checks`

**Permission:** Member role + **Author** team permission on the container's datastore (**Drafter** when `status` is `"Draft"`).

> **Example: Create an Expected Schema check (every accepted field)**
>
> ```bash
> curl -X POST "https://your-instance.qualytics.io/api/quality-checks" \
>   -H "Authorization: Bearer YOUR_TOKEN" \
>   -H "Content-Type: application/json" \
>   -d '{
>       "description": "The ORDERS extract must match the agreed layout.",
>       "rule": "expectedSchema",
>       "fields": [],
>       "container_id": 145,
>       "filter": null,
>       "properties": {"list": ["o_orderkey", "o_custkey", "o_orderstatus", "o_totalprice"], "allow_other_fields": false},
>       "tags": ["schema", "contract"],
>       "additional_metadata": {"jira": "DATA-9801"},
>       "template_id": null,
>       "status": "Active",
>       "owner_id": 7,
>       "default_anomaly_assignee_id": 12
>   }'
> ```

### Field notes

| Field | Required | Notes |
| --- | --- | --- |
| `description` | Yes | Free-text description shown in the UI. |
| `rule` | Yes | Must be `"expectedSchema"`. |
| `fields` | No | Expected Schema does not select columns on the check itself; the declaration lives under `properties`. Send an empty array `[]` or omit. |
| `container_id` | Yes | ID of the container (table or file) the check runs against. |
| `filter` | No | Not supported by this rule. Send `null` or omit it; a non-empty expression is rejected with `422`. |
| `properties` | Yes | Object holding the declaration and the extra-fields policy. See [above](https://userguide.qualytics.io/data-quality-checks/expected-schema/api/#the-properties-object). |
| `tags` | No | List of tag names applied to the check for filtering and organization. |
| `additional_metadata` | No | Free-form key-value pairs (typically links to catalog entries, tickets, governance records). |
| `template_id` | No | Send `null` or omit it. Expected Schema is not offered as a template rule type, so no Check Template carries this rule. |
| `status` | No | `"Active"` (default) or `"Draft"`. Draft checks are not evaluated by Scans. |
| `owner_id` | No | ID of the user who owns the check. Defaults to the user creating the check when omitted. |
| `default_anomaly_assignee_id` | No | ID of the user automatically assigned to anomalies produced by the check. |

Two payload fields exist for other rule types but do not apply here:

- `coverage` is not supported. The rule reads the container's structure, not its rows, so there is no per-row violation rate; any value other than `1` is rejected with `422`.
- `anomaly_message_field` is ignored. Expected Schema emits a Shape Anomaly only, and Shape Anomalies always use the fixed message.

## Read

**Endpoint:** `GET /api/quality-checks/{id}`

**Permission:** Member role + **Reporter** team permission on the check's datastore.

> **Example: Retrieve a check by ID**
>
> ```bash
> curl -X GET "https://your-instance.qualytics.io/api/quality-checks/101" \
>   -H "Authorization: Bearer YOUR_TOKEN"
> ```

## Update

**Endpoint:** `PUT /api/quality-checks/{id}`

**Permission:** Member role + **Author** team permission on the check's datastore (**Drafter** when the check stays Draft).

The `PUT` endpoint requires `description`; include the check's current description (or a new one) along with the fields you want to change. Send the whole `properties` object: partial property updates are not merged.

> **Example: Tolerate undeclared columns**
>
> ```bash
> curl -X PUT "https://your-instance.qualytics.io/api/quality-checks/101" \
>   -H "Authorization: Bearer YOUR_TOKEN" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "description": "The ORDERS extract must carry the agreed fields; extras are allowed.",
>     "properties": {
>         "list": ["o_orderkey", "o_custkey", "o_orderstatus", "o_totalprice"],
>         "allow_other_fields": true
>     }
>   }'
> ```

A `PUT` can update most fields on an existing Expected Schema check. Three values stay immutable: the rule type, the container the check is attached to, and `template_id`. If either of the first two needs to change, delete the check and create a new one.

> **Info: Editable vs Immutable on PUT**
>
> **Editable**
>
> - `description`
> - `properties.list` (the declaration)
> - `properties.allow_other_fields`
> - `tags`
> - `additional_metadata`
> - `status`
> - `owner_id`
> - `default_anomaly_assignee_id`
>
> **Immutable**
>
> - `rule`
> - `container_id`
> - `template_id`

## Delete

**Endpoint:** `DELETE /api/quality-checks/{id}`

**Permission:** Member role + **Author** team permission on the check's datastore.

Three query parameters control what happens, mirroring the two-stage flow in the UI:

| Parameter | Default | Description |
| --- | --- | --- |
| `archive` | `true` | When `true`, the check is archived and can be restored later. When `false`, the check is permanently deleted. |
| `status` | `Discarded` | The archive resolution: `Discarded` (no longer relevant) or `Invalid` (wrong and suppressed from future AI generation). Only used when `archive=true`. |
| `delete_anomalies` | `true` | Whether to permanently delete the anomalies the check produced. A permanent delete (`archive=false`) always removes them. |

> **Example: Archive a check, keeping its anomalies**
>
> ```bash
> curl -X DELETE "https://your-instance.qualytics.io/api/quality-checks/101?archive=true&status=Discarded&delete_anomalies=false" \
>   -H "Authorization: Bearer YOUR_TOKEN"
> ```

> **Example: Delete a check permanently**
>
> ```bash
> curl -X DELETE "https://your-instance.qualytics.io/api/quality-checks/101?archive=false" \
>   -H "Authorization: Bearer YOUR_TOKEN"
> ```

## Error responses

| Status | Description |
| --- | --- |
| `400 Bad Request` | A business-logic conflict prevents the operation (for example, changing properties while the check is archived, or switching an archived check between `Discarded` and `Invalid`). |
| `401 Unauthorized` | Missing or invalid API token. |
| `403 Forbidden` | The caller lacks the required team permission on the check's datastore. |
| `404 Not Found` | The check ID does not exist. |
| `422 Unprocessable Entity` | The payload fails schema validation (for example, `description` missing on `PUT`, or `properties.list` is missing or empty). |

*Last updated: September 29, 2026.*
