# Freshness Check API

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

This page documents how to create and manage a Freshness check via the REST API. The check uses the standard Quality Checks endpoints: set `rule` to `freshness` and set the Maximum Age 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/freshness/deep-dive/permissions/) for the full matrix.

## The `properties` object

Freshness carries its rule-specific configuration under `properties`:

| Field | Required | Type | Description |
| --- | --- | --- | --- |
| `value` | Yes | `integer` | The Maximum Age in **milliseconds**: `21600000` is 6 hours, `86400000` is 1 day. The app converts the unit you pick into milliseconds. |

## Create

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

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

> **Example: Create a Freshness 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": "customers_snapshot is refreshed at least every 6 hours.",
>       "rule": "freshness",
>       "fields": [],
>       "container_id": 311,
>       "filter": null,
>       "properties": {"value": 21600000},
>       "tags": ["crm", "sla"],
>       "additional_metadata": {"runbook": "https://wiki.example.com/crm-extract"},
>       "template_id": null,
>       "status": "Active",
>       "owner_id": 7,
>       "default_anomaly_assignee_id": 18
>   }'
> ```

### Field notes

| Field | Required | Notes |
| --- | --- | --- |
| `description` | Yes | Free-text description shown in the UI. |
| `rule` | Yes | Must be `"freshness"`. |
| `fields` | No | Freshness does not evaluate a field. Send an empty array `[]` or omit. |
| `container_id` | Yes | ID of the container (table or file) whose last modification time is checked. |
| `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 Maximum Age. See [above](https://userguide.qualytics.io/data-quality-checks/freshness/api/#the-properties-object). |
| `tags` | No | List of tag names applied to the check. Anomalies the check produces inherit them. |
| `additional_metadata` | No | Free-form key-value pairs (typically links to catalog entries, tickets, governance records). |
| `template_id` | No | ID of a Check Template whose rule type is Freshness. The template then controls the check's properties. Send `null` or omit it to configure the check directly. |
| `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 last modification time, 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. Freshness 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"
> ```

The response's `inferred` field is `true` for an AI Managed check. Its `last_asserted` field is empty until a Scan has asserted the check.

## Update

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

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

Every `PUT` requires `description` and the full `properties` object with its `value`. Repeat the check's current `properties` even when changing only its description, tags, or other metadata: a request without them returns `422`.

> **Example: Relax the Maximum Age to 8 hours**
>
> ```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": "customers_snapshot is refreshed at least every 8 hours.",
>     "properties": {"value": 28800000}
>   }'
> ```

A `PUT` can update most fields on an existing Freshness check. Three values stay immutable: the rule type, the container the check is attached to, and `template_id`. Updating `properties.value` on an AI Managed check sets `inferred` to `false`, which stops automatic updates.

> **Info: Editable vs Immutable on PUT**
>
> **Editable**
>
> - `description`
> - `properties.value` (the Maximum Age)
> - `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. |
| `409 Conflict` | The container already has an Active Freshness check. |
| `422 Unprocessable Entity` | The payload fails schema validation (for example, `description` missing on `PUT`, `properties.value` missing, or a non-empty `filter`). |

*Last updated: October 13, 2026.*
