Skip to content
sproutboatDocs
Esc
↑↓navigate↵open⌘Jpreview

Query D1

Runs statements on the host that holds the app’s database. With only data:read the database is opened read-only (a write is refused); changing data needs data:write. Up to 100 statements, 4 MiB of SQL, 100 bound parameters per statement. transaction defaults to true (all or nothing). A first-filter guard refuses ATTACH, PRAGMA (except introspection), load_extension and transaction control. This route is audited (no SQL text is stored) and counts against the data-route limits.

POST/v1/apps/{project}/d1/{binding}/query
Authorization
AuthorizationBearer token · headerrequired

A team API key, sbk_..., from Settings, API keys.

or
x-api-keyAPI key · headerrequired

The same key, in a header of its own.

Path parameters
projectstringrequired

The app's name, unique within the team. 3 to 51 characters (or 1), lowercase letters, digits and dashes, not starting or ending with a dash.

matches ^[a-z0-9](?:[a-z0-9-]{1,49}[a-z0-9])?$
bindingstringrequired

The D1 binding name from the app's config, for example DB.

Request body
requiredapplication/json
statementsobject[]required
max items 100
Show properties
Array of object
sqlstringrequired
paramsstring | number | boolean[]
max items 100
transactionboolean
default: true
Responses
200

One result per statement, in the shape of Cloudflare's D1 REST API.

resultsobject[]
Show properties
Array of object
successboolean
resultsobject[]
metaobject
400

The request is malformed (invalid), a statement is refused (refused) or SQLite failed it (sql-error, with statement).

One of:
ErrorInvalid
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:invalid
ErrorRefused
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:refused
ErrorSqlError
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:sql-error
statementinteger

The index of the failing statement in statements.

min 0
ErrorPlain
errorstringrequired

A message for people. Do not parse it.

reasonstring

A stable, machine-readable cause, when there is one.

pathstring

The request field at fault.

needstring

The grant a 403 asks for, app:write for example.

retry_after_sinteger
401

No key, or an invalid, expired or revoked key (unknown or missing API token, invalid, expired or revoked API key). No reason.

errorstringrequired

A message for people. Do not parse it.

reasonstring

A stable, machine-readable cause, when there is one.

pathstring

The request field at fault.

needstring

The grant a 403 asks for, app:write for example.

retry_after_sinteger
403

The key lacks a grant (reason: forbidden, need: "<resource>:<action>").

errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:forbidden
needstringrequired

The grant, as <resource>:<action>, for example app:write.

404

No such app (message only), database (no-database), bucket (no-bucket) or object (no-object).

One of:
ErrorNoDatabase
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:no-database
ErrorNoBucket
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:no-bucket
ErrorNoObject
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:no-object
ErrorPlain
errorstringrequired

A message for people. Do not parse it.

reasonstring

A stable, machine-readable cause, when there is one.

pathstring

The request field at fault.

needstring

The grant a 403 asks for, app:write for example.

retry_after_sinteger
409

D1: remote writes are off for this database (capture-active), or its file is unusable (bad-database).

One of:
ErrorCaptureActive
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:capture-active
ErrorBadDatabase
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:bad-database
413

The request is over the limit (too-large) or the result is over 8 MiB (result-too-large).

One of:
ErrorTooLarge
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:too-large
ErrorResultTooLarge
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:result-too-large
ErrorPlain
errorstringrequired

A message for people. Do not parse it.

reasonstring

A stable, machine-readable cause, when there is one.

pathstring

The request field at fault.

needstring

The grant a 403 asks for, app:write for example.

retry_after_sinteger
422

The statement needs more memory than the host allows (reason: memory-limit).

errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:memory-limit
429

Data routes: too many requests in flight or an empty bucket (rate; note retry_after, without _s), or key-rate-limited. Honor Retry-After.

One of:
ErrorKeyRateLimited
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:key-rate-limited
retry_after_sintegerrequired

Seconds to wait; also the Retry-After header.

ErrorRate
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:rate
retry_afterintegerrequired

Seconds to wait; also the Retry-After header.

502

The host agent answered something the Cloud could not handle (reason: agent-error).

errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:agent-error
503

The app's host is not reachable (host-unavailable), is busy with the app's data (busy, Retry-After), or the audit log could not record the request (audit-unavailable). Retry shortly.

One of:
ErrorHostUnavailable
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:host-unavailable
ErrorBusy
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:busy
retry_afterintegerrequired

Seconds to wait; also the Retry-After header.

ErrorAuditUnavailable
errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:audit-unavailable
504

The host did not answer in time (reason: timeout). committed says whether a write may have been applied.

errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:timeout
committedstringrequired
Allowed:nounknown
507

The app's storage quota on its host is full (reason: quota-exceeded).

errorstringrequired

A message for people. Do not parse it.

reasonstringrequired
Allowed:quota-exceeded
Request
curl -X POST 'https://dash.sproutboat.com/v1/apps/my-app/d1/string/query' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "statements": [
    {
      "sql": "string",
      "params": [
        "string"
      ]
    }
  ],
  "transaction": true
}'
Response
{
  "results": [
    {
      "success": true,
      "results": [
        {}
      ],
      "meta": {}
    }
  ]
}