---
title: "Query an owned site's database"
description: "Runs SQL against the site's current database, on the edge or its VM."
canonical: "https://www.cool.computer/docs/api-reference/publishing/query-an-owned-sites-database"
---
# Query an owned site's database

> Runs SQL against the site's current database, on the edge or its VM.

```http
POST https://api.cool.computer/api/computers/{id}/database/query
```

Runs SQL against the site's current database, on the edge or its VM. A statements array runs as one D1 batch. A response over 1 MiB is refused with 413 database_result_too_large: select fewer rows (LIMIT) or columns. A query has no idempotency key, and its writes can commit before a 413, a timeout or a lost response is reported, so read the data before rerunning a write. Callers: the computer owner's account bearer or browser session.

## Authorization

- A Cool Computers API key, user access token, or claimed agent access token in the Authorization header. Follow https://www.cool.computer/auth.md for agent registration and https://www.cool.computer/authentication.md for direct user credentials.

## Parameters

- `id` (path, string, at least 1 characters, required): The computer's name, such as agent-atlas, or its id (cmp_…). Every caller may use either, the computer's own runtime token included.

## Request body

Required.

- `application/json` (object or object)
  - object
    - `sql` (string, at least 1 characters, required)
    - `params` (array of string or number or null): Positional SQLite parameters. Integers must be within ±(2^53−1); bind larger integers as strings.
  - object
    - `statements` (array of object, at least 1 items, required)
      - `sql` (string, at least 1 characters, required)
      - `params` (array of string or number or null): Positional SQLite parameters. Integers must be within ±(2^53−1); bind larger integers as strings.

## Responses

- `200`: One result per statement, in order.
  - `application/json` (object)
    - `results` (array of object, required)
      - `columns` (array of string, required): The result's column names in the statement's order, which the row objects do not keep. A name used twice appears once, and its row objects keep the later value. Empty when the statement returns no columns.
      - `results` (array of object, required): The rows, each an object keyed by column name.
      - `meta` (object, required)
        - `changes` (integer, required)
        - `last_row_id` (integer, required)
      - `success` (boolean, required)
- `400`: A machine-readable API error with a stable code and recovery instruction.
- `401`: Unauthorized.
- `403`: A machine-readable API error with a stable code and recovery instruction.
- `404`: A machine-readable API error with a stable code and recovery instruction.
- `409`: A machine-readable API error with a stable code and recovery instruction.
- `413`: A machine-readable API error with a stable code and recovery instruction.
- `422`: A machine-readable API error with a stable code and recovery instruction.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X POST "https://api.cool.computer/api/computers/$PARAM_ID/database/query" \
  -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" \
  --data '{"sql":"SELECT 1"}'
```
