`POST /api/apps/{id}/backend/{function_name}` -- invoke a declared backend function synchronously (ADR 0053). The author-fixed SQL runs under the db_query/db_execute guard with RLS `supacloud.app_id` injected; only the function name + positional args cross the wire, so a caller cannot inject SQL. Authenticated by the browser App-backend token (`Bearer scab_…`, confined to this App), the per-deployment App token (`Bearer scwa_…`) or a session.
const url = 'https://example.com/api/apps/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/backend/example';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"args":["example"]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/api/apps/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/backend/example \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "args": [ "example" ] }'POST /api/apps/{id}/backend/{function_name} – invoke a declared backend
function synchronously (ADR 0053). The author-fixed SQL runs under the
db_query/db_execute guard with RLS supacloud.app_id injected; only the
function name + positional args cross the wire, so a caller cannot inject
SQL. Authenticated by the browser App-backend token (Bearer scab_…,
confined to this App), the per-deployment App token (Bearer scwa_…) or a
session.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”App id
Declared backend function name
Request Bodyrequired
Section titled “Request Bodyrequired”POST /api/apps/{id}/backend/{function_name} request body – the positional
arguments bound to the function’s $1..$n placeholders. The function name is
a path segment, not a body field; the SQL is author-fixed in the manifest.
object
Positional arguments, bound in order. Empty for a no-arg function.
Example generated
{ "args": [ "example" ]}Responses
Section titled “Responses”Function result (rows / affected count).
POST /api/apps/{id}/backend/{function_name} response. operation tells the
caller how to read the payload: a query returns rows with
row_count = rows.len(); an execute returns the affected-row count in
row_count and any RETURNING rows in rows.
object
The invoked function name.
query or execute.
script only – the arbitrary JSON value the script returned (a query/
execute returns null here and carries its payload in rows). Omitted
from the wire when absent, so the query/execute shape is unchanged. Typed
as an UNCONSTRAINED value (a script may return an array/scalar/object) so the
generated zod is z.unknown(), not a z.object({}) that would reject a
non-object return or strip an object’s keys (the §10 result-shape defect).
Affected-row count (execute) or returned-row count (query).
Query rows, or DML RETURNING rows (empty when the function does not
return). Each row is a free-form object — typed as a key-preserving map so
the generated zod becomes z.array(z.object({}).catchall(...)) instead of a
strict z.array(z.object({})) that zod v4 strips every row column from on
parse (the §10 result-table contract defect). Mirrors the proven
audit_events.payload_redacted shape.
object
Example generated
{ "function": "example", "operation": "example", "result": "example", "row_count": 1, "rows": [ { "additionalProperty": "example" } ]}Bad args, mis-declared SQL, or no app_db bound.
The canonical JSON body of every error response. Every AppError serializes as
this exact shape; code is the generated stable machine-readable vocabulary.
object
Present only on an MCP budget refusal (429) — the refusing layer + retry hint.
object
The refusing layer.
The layer’s budget.
Seconds until a retry can pass, or null when it never will for this session.
Calls already counted in the layer.
Machine-readable, stable error code.
Present only on a quota-exceeded 403 — the inline upgrade-CTA payload.
object
The entitlement feature key that was hit, e.g. apps.max_count.
The plan’s limit for this key.
Where to send the user to upgrade.
Current usage (count or bytes, per the key).
Human-readable message (the server’s English text; the client may localize
by code).
Present on a launch refusal (400/403/409) — the structured facts only the refusing class can fill: occupancy, exhausted budget, or required labels.
object
Weighted workspace slots already held by starting/running agent runs.
The budget cap that refused.
Effective spend of the refusing budget scope (spend + in-flight reservations).
The workspace’s configured agent-concurrency cap.
The provider whose budget cap refused; absent for the workspace-wide cap.
Runner labels a fail-policy placement required and no runner offered.
Example
{ "code": "not_found"}Missing/invalid App token or session, or an App-backend token whose member is no longer in the workspace.
The canonical JSON body of every error response. Every AppError serializes as
this exact shape; code is the generated stable machine-readable vocabulary.
object
Present only on an MCP budget refusal (429) — the refusing layer + retry hint.
object
The refusing layer.
The layer’s budget.
Seconds until a retry can pass, or null when it never will for this session.
Calls already counted in the layer.
Machine-readable, stable error code.
Present only on a quota-exceeded 403 — the inline upgrade-CTA payload.
object
The entitlement feature key that was hit, e.g. apps.max_count.
The plan’s limit for this key.
Where to send the user to upgrade.
Current usage (count or bytes, per the key).
Human-readable message (the server’s English text; the client may localize
by code).
Present on a launch refusal (400/403/409) — the structured facts only the refusing class can fill: occupancy, exhausted budget, or required labels.
object
Weighted workspace slots already held by starting/running agent runs.
The budget cap that refused.
Effective spend of the refusing budget scope (spend + in-flight reservations).
The workspace’s configured agent-concurrency cap.
The provider whose budget cap refused; absent for the workspace-wide cap.
Runner labels a fail-policy placement required and no runner offered.
Example
{ "code": "not_found"}App token does not authorize this app.
The canonical JSON body of every error response. Every AppError serializes as
this exact shape; code is the generated stable machine-readable vocabulary.
object
Present only on an MCP budget refusal (429) — the refusing layer + retry hint.
object
The refusing layer.
The layer’s budget.
Seconds until a retry can pass, or null when it never will for this session.
Calls already counted in the layer.
Machine-readable, stable error code.
Present only on a quota-exceeded 403 — the inline upgrade-CTA payload.
object
The entitlement feature key that was hit, e.g. apps.max_count.
The plan’s limit for this key.
Where to send the user to upgrade.
Current usage (count or bytes, per the key).
Human-readable message (the server’s English text; the client may localize
by code).
Present on a launch refusal (400/403/409) — the structured facts only the refusing class can fill: occupancy, exhausted budget, or required labels.
object
Weighted workspace slots already held by starting/running agent runs.
The budget cap that refused.
Effective spend of the refusing budget scope (spend + in-flight reservations).
The workspace’s configured agent-concurrency cap.
The provider whose budget cap refused; absent for the workspace-wide cap.
Runner labels a fail-policy placement required and no runner offered.
Example
{ "code": "not_found"}App or function not found.
The canonical JSON body of every error response. Every AppError serializes as
this exact shape; code is the generated stable machine-readable vocabulary.
object
Present only on an MCP budget refusal (429) — the refusing layer + retry hint.
object
The refusing layer.
The layer’s budget.
Seconds until a retry can pass, or null when it never will for this session.
Calls already counted in the layer.
Machine-readable, stable error code.
Present only on a quota-exceeded 403 — the inline upgrade-CTA payload.
object
The entitlement feature key that was hit, e.g. apps.max_count.
The plan’s limit for this key.
Where to send the user to upgrade.
Current usage (count or bytes, per the key).
Human-readable message (the server’s English text; the client may localize
by code).
Present on a launch refusal (400/403/409) — the structured facts only the refusing class can fill: occupancy, exhausted budget, or required labels.
object
Weighted workspace slots already held by starting/running agent runs.
The budget cap that refused.
Effective spend of the refusing budget scope (spend + in-flight reservations).
The workspace’s configured agent-concurrency cap.
The provider whose budget cap refused; absent for the workspace-wide cap.
Runner labels a fail-policy placement required and no runner offered.
Example
{ "code": "not_found"}