---
title: "Schemas"
description: "REST endpoints for schemas. Bearer-auth required."
section: "API"
group: "REST"
order: 56
---

## GET /api/schemas

List schemas with pagination.

**Query parameters**

- `limit` (optional): Page size (1–100, default 100).
- `after` (optional): Keyset cursor — return the page after this row (next page).
- `before` (optional): Keyset cursor — return the page before this row (prev page).
- `ids` (optional): Comma-separated list of IDs. Narrows results to these IDs within the caller's accessible scope (does not bypass access checks).
- `filter` (optional): Nested filter expression (`<Entity>Filter`): AND/OR/NOT + per-field comparison operators + relation traversal. JSON-encoded on the query string.
- `orderBy` (optional): Multi-key sort (`<Entity>OrderBy[]`): array of `{ field: direction }` applied in order. Directions: asc/desc plus the four explicit nulls variants. JSON-encoded on the query string.
- `workspace_id` (optional): Filter to schemas in this workspace. When omitted, returns schemas across every workspace the caller is a member of (admins see all). System schemas are always included.
- `include_deleted` (optional): Soft-deleted schema visibility. `false` (default) — active rows only. `true` — active plus soft-deleted. `only` — soft-deleted only (trash view).
- `name` (optional): Case-insensitive substring match on name.
- `source` (optional): Narrow by source. `workspace` = this workspace's schemas plus those visible via installed integrations; `system` = only global system schemas; `integration` = only schemas made visible by installed integrations; omit = union.
- `system` (optional): Shorthand: filter where `system` equals this value.
- `created_by` (optional): Shorthand: filter where `createdBy` equals this value.
- `retention_tier` (optional): Shorthand: filter where `retentionTier` equals this value.

**Response**

```json
{
  "data": [
    {
      "id": "<...>",
      "workspaceId": "<...>",
      "slug": "<...>",
      "name": "<...>",
      "description": "<...>",
      "definition": "<...>",
      "system": "<...>",
      "createdBy": "<...>",
      "deletedAt": "<...>",
      "retentionTier": "<...>",
      "createdAt": "<...>",
      "updatedAt": "<...>"
    }
  ],
  "pageInfo": {
    "total": "number",
    "hasNextPage": "boolean",
    "hasPreviousPage": "boolean",
    "startCursor": "string",
    "endCursor": "string"
  }
}
```

## POST /api/schemas

Create schema

**Request body**

```json
{
  "workspaceId": "string",
  "name": "string",
  "slug": "string",
  "description?": "string",
  "definition?": {}
}
```

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "definition": {},
  "system": "boolean",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## GET /api/schemas/{id}

Get a single schema by ID.

**Path parameters**

- `id` (required): Schema to retrieve.

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "definition": {},
  "system": "boolean",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## PATCH /api/schemas/{id}

Update schema

**Path parameters**

- `id` (required): The schema's prefixed ID (e.g. `sch_...`).

**Request body**

```json
{
  "name?": "string",
  "description?": "string",
  "definition?": {}
}
```

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "definition": {},
  "system": "boolean",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## DELETE /api/schemas/{id}

Delete schema

Soft-delete a schema. Restore via `POST /api/schemas/{id}/restore` before retention expires.

**Path parameters**

- `id` (required): The schema's prefixed ID (e.g. `sch_...`).

**Response**

```json
{
  "success": "boolean"
}
```

## DELETE /api/schemas/{id}/purge

Permanently delete a soft-deleted schema.

**Path parameters**

- `id` (required): Soft-deleted schema to permanently delete.

**Response**

```json
{
  "success": "boolean"
}
```

## POST /api/schemas/{id}/restore

Restore a soft-deleted schema.

**Path parameters**

- `id` (required): Soft-deleted schema to restore.

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "definition": {},
  "system": "boolean",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```
