Skip to content

Run a saved query

POST
/api/v1/bi/saved-queries/{id}/run
curl --request POST \
--url https://api.justcrawl.io/api/v1/bi/saved-queries/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/run \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "sql": "example" }'

Resolves stored content and immutable execution scope on the server. Optional SQL is a dashboard edit override and inherits that scope.

id
required
string format: uuid
Idempotency-Key
string format: uuid
Media typeapplication/json
object
sql

Optional dashboard-only SQL override.

string
Examplegenerated
{
"sql": "example"
}

Accepted saved-query execution

Media typeapplication/json

Accepted BI execution. A saved replay also includes its saved-query identity and immutable scope.

object
jobId
required
string format: uuid
replayed
required
boolean
submissionKey
string format: uuid
nullable
status
required
string
Allowed values: queued running success failed canceled
dryRun
required
object
key
additional properties
any
sqlPreview
string
nullable
results

One page of result rows. Returned bare by GET /api/v1/bi/queries/{id}/results, but nested under results by POST /api/v1/bi/queries when the sync-wait window catches a completed query. The two are not interchangeable.

object
rows
required
Array<object>
object
key
additional properties
any
page
required
integer
pageSize
required
integer
totalRows
required

Total rows materialized for this query. -1 when unknown.

integer
hasMore
required
boolean
historyCoverage

Present only when a structured aggregate left out readings older than the typed-column history backfill. Those readings have no typed values, so measures and typed filters could not include them. Absent when the answer covers every matching reading.

object
backfillHorizon
required

Readings created before this instant may be missing from the result.

string format: date-time
preHorizonRows
required

Matching source readings excluded for lack of typed history.

integer
>= 1
savedQueryId
string format: uuid
savedQueryName
string
sourceQueryId
string format: uuid
nullable
scopeKind
string
Allowed values: org agent
scopeAgentId
string format: uuid
nullable
error

The query’s own failure detail — not an HTTP error envelope.

object
code
string
Allowed values: syntax_error statement_timeout rls_denied too_many_queries kill_switched canceled transient
message
string
retriable
boolean
Example
{
"status": "queued",
"scopeKind": "org",
"error": {
"code": "syntax_error"
}
}

Invalid idempotency key, forged execution context, or SQL override (invalid_idempotency_key, invalid_execution_context, invalid_sql, syntax_error, kill_switched)

Media typeapplication/json
object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
error
required
object
code
string
Allowed values: invalid_idempotency_key invalid_execution_context invalid_sql syntax_error kill_switched
Example
{
"error": {
"code": "invalid_idempotency_key"
}
}

Missing or invalid authentication token

Media typeapplication/json
object
error
string
Example
{
"error": "Missing or invalid authentication token"
}

Access to the BI surface itself is refused. no_org and feature_disabled fire on every BI route from the mount guard, before any handler runs — feature_disabled is the first response most new integrations see, because the SQL console is entitled per organization. Permission and verified-email gates use insufficient_permissions and email_not_verified; rls_denied and kill_switched come from the engine. This response never describes resource-level authorization: an id you do not own returns 404, not 403.

Media typeapplication/json
object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
error
required
object
code
string
Allowed values: no_org feature_disabled insufficient_permissions email_not_verified authentication_required user_not_found rls_denied kill_switched
Example
{
"error": {
"code": "feature_disabled",
"message": "SQL console is not enabled for this organization",
"docs_url": "https://docs.justcrawl.io/guides/errors/bi",
"request_id": "req_9f3a1c7e2b40"
}
}

Not found, or not owned by your organization. The two are deliberately indistinguishable so cross-tenant existence cannot be probed

Media typeapplication/json

Error envelope returned by every /api/v1/bi/* handler error. Unlike the rest of the API — where the structured shape is opt-in via the application/vnd.justcrawl.v1+json media type — a BI handler always emits it, and all four fields are always present. The one exception: 401s from missing or invalid auth are rejected by shared middleware before any BI handler runs, so they carry the flat { "error": "<message>" } shape (Error schema) instead — see the Unauthorized response on each operation.

object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
Example
{
"error": {
"code": "not_found",
"message": "Query not found",
"docs_url": "https://docs.justcrawl.io/guides/errors/not_found",
"request_id": "req_9f3a1c7e2b40"
}
}

Stored content lacks a proven scope, or the idempotency key belongs to another request (saved_query_not_executable, idempotency_conflict)

Media typeapplication/json
object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
error
required
object
code
string
Allowed values: saved_query_not_executable idempotency_conflict
Example
{
"error": {
"code": "saved_query_not_executable"
}
}

Organization query admission is full (too_many_queries)

Media typeapplication/json
object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
error
required
object
code
string
Allowed values: too_many_queries
Example
{
"error": {
"code": "too_many_queries"
}
}

Unexpected server error. Full detail goes to the logs and PostHog $exception capture, never the response

Media typeapplication/json

Error envelope returned by every /api/v1/bi/* handler error. Unlike the rest of the API — where the structured shape is opt-in via the application/vnd.justcrawl.v1+json media type — a BI handler always emits it, and all four fields are always present. The one exception: 401s from missing or invalid auth are rejected by shared middleware before any BI handler runs, so they carry the flat { "error": "<message>" } shape (Error schema) instead — see the Unauthorized response on each operation.

object
error
required
object
code
required

Stable, machine-readable error code. Match on this, not on message.

string
message
required

Customer-safe description. Never raw exception or driver text, with one deliberate exception: a syntax_error (SQLSTATE 42601) passes the database’s own message through verbatim, because it describes SQL the caller wrote themselves and names nothing they could not already see — see the root CLAUDE.md §Error reporting for the full carve-out.

string
docs_url
required

Reference page for this code. Codes shared with the rest of the API have their own page; the BI-local vocabulary points at the single BI errors page that tabulates all of them.

string format: uri
request_id
required

Correlation id. Identical to the X-Request-ID response header — quote either one to support.

string
Example
{
"error": {
"code": "internal_error",
"message": "Failed to list queries",
"docs_url": "https://docs.justcrawl.io/guides/errors/internal_error",
"request_id": "req_9f3a1c7e2b40"
}
}