---
title: "Databases"
description: "REST endpoints for databases. Bearer-auth required."
section: "API"
group: "REST"
order: 23
---

## GET /api/databases

List databases 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 databases in this workspace. When omitted, returns databases across every workspace the caller is a member of (admins see all).
- `include_deleted` (optional): Soft-deleted database visibility. `false` (default) — active rows only. `true` — active plus soft-deleted. `only` — soft-deleted only.
- `name` (optional): Case-insensitive substring match on name.
- `source` (optional): Narrow by source. `workspace` = this workspace's rows plus those visible via installed integrations; `integration` = only rows made visible by installed integrations; omit = union.
- `kind` (optional): Shorthand: filter where `kind` equals this value.
- `status` (optional): Shorthand: filter where `status` 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": "<...>",
      "kind": "<...>",
      "status": "<...>",
      "cfResourceId": "<...>",
      "cfResourceName": "<...>",
      "createdBy": "<...>",
      "deletedAt": "<...>",
      "retentionTier": "<...>",
      "createdAt": "<...>",
      "updatedAt": "<...>"
    }
  ],
  "pageInfo": {
    "total": "number",
    "hasNextPage": "boolean",
    "hasPreviousPage": "boolean",
    "startCursor": "string",
    "endCursor": "string"
  }
}
```

## POST /api/databases

Create database

**Request body**

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

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "kind": "d1",
  "status": "provisioning | ready | failed",
  "cfResourceId": "string",
  "cfResourceName": "string",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## GET /api/databases/{id}

Get a database by ID.

**Path parameters**

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

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "kind": "d1",
  "status": "provisioning | ready | failed",
  "cfResourceId": "string",
  "cfResourceName": "string",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## PATCH /api/databases/{id}

Update database

**Path parameters**

- `id` (required): The database's prefixed ID (e.g. `dbs_...`).

**Request body**

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

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "kind": "d1",
  "status": "provisioning | ready | failed",
  "cfResourceId": "string",
  "cfResourceName": "string",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## DELETE /api/databases/{id}

Soft-delete a database. The underlying D1 instance stays live until purge.

**Path parameters**

- `id` (required): Database to soft-delete.

**Response**

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

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

Permanently delete a soft-deleted database.

**Path parameters**

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

**Response**

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

## POST /api/databases/{id}/query

Execute SQL

**Path parameters**

- `id` (required): The database's prefixed ID (e.g. `dbs_...`).

**Request body**

```json
{
  "query": "string",
  "params?": ["any"]
}
```

**Response**

```json
{
  "columns": ["<...>"],
  "rows": [{}],
  "rowsRead?": "number",
  "rowsWritten?": "number",
  "durationMs": "number"
}
```

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

Restore a soft-deleted database.

**Path parameters**

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

**Response**

```json
{
  "id": "string",
  "workspaceId": "string",
  "slug": "string",
  "name": "string",
  "description": "string",
  "kind": "d1",
  "status": "provisioning | ready | failed",
  "cfResourceId": "string",
  "cfResourceName": "string",
  "createdBy": "string",
  "deletedAt": "string",
  "retentionTier": "any",
  "createdAt": "string",
  "updatedAt": "string"
}
```

## GET /api/databases/{id}/tables

List tables

**Path parameters**

- `id` (required): The database's prefixed ID (e.g. `dbs_...`).

**Response**

```json
{
  "tables": ["<...>"]
}
```

## GET /api/databases/{id}/tables/{tableName}

Describe table

**Path parameters**

- `id` (required): The database's prefixed ID (e.g. `dbs_...`).
- `tableName` (required): Table name within the database.

**Response**

```json
{
  "name": "string",
  "columns": ["<...>"],
  "rowCount": "number"
}
```

## GET /api/databases/{id}/tables/{tableName}/rows

Browse table rows

**Path parameters**

- `id` (required): The database's prefixed ID (e.g. `dbs_...`).
- `tableName` (required): Table name within the database.

**Query parameters**

- `limit` (optional): Max rows to return (1-500, default 100).
- `offset` (optional): Skip this many rows from the start.

**Response**

```json
{
  "columns": ["<...>"],
  "rows": [{}],
  "total": "number",
  "limit": "number",
  "offset": "number"
}
```
