> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bijection HTTP API

The public functions that define a deployment are exposed at public HTTP
endpoints.

## Bijection value format

Each of the HTTP APIs take a `format` query param that describes how documents
are formatted. Currently the only supported value is `json`. See our
[types page](https://docs.bijection.com/database/types.md#bijection-values) for details. Note that for
simplicity, the `json` format does not support all Bijection data types as input,
and uses overlapping representation for several data types in output. We plan to
add a new format with support for all Bijection data types in the future.

## API authentication

The Functions API can be optionally authenticated as a user via a bearer token
in a `Authorization` header. The value is `Bearer <access_key>` where the key is
a token from your auth provider. See the
[under the hood](https://docs.bijection.com/access/authentication/providers/clerk.md) portion of the Clerk docs for
details on how this works with Clerk.

Streaming export and streaming import are not available: Bijection deployments
refuse them. Deployment administration requests require an admin key in the
`Authorization` header, sent as `Bijection <admin_key>`. Admin keys are
short-lived and issued by the management service; see the
[Deployment Platform API](https://docs.bijection.com/reference/http/deployment) for how to obtain one. A
deploy key is not accepted by the deployment directly.

## Functions API

### POST `/api/query`, `/api/mutation`

These HTTP endpoints allow you to call Bijection functions and get the result as a
value.

You can find your backend deployment URL on the console
[Settings](https://docs.bijection.com/operate/installations) page, then the API URL will be
`<BIJECTION_URL>/api/query` etc., for example:

> [tab] Shell
>
> ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> curl https://acoustic-panther-728.bijection.cloud/api/query \
>    -d '{"path": "messages:list", "args": {}, "format": "json"}' \
>    -H "Content-Type: application/json"
> ```

> [tab] NodeJS
>
> ```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> const url = "https://acoustic-panther-728.bijection.cloud/api/query";
> const request = { path: "messages:list", format: "json" };
>
> const response = fetch(url, {
>   method: "POST",
>   headers: {
>     "Content-Type": "application/json",
>   },
>   body: JSON.stringify(request),
> });
> ```

> [tab] Python
>
> ```py theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> import requests
>
> url = "https://acoustic-panther-728.bijection.cloud/api/query"
> headers = {"accept": "application/json"}
> body = {"path": "messages:list", "args": {}, "format": "json"}
>
> response = requests.post(url, headers=headers, json=body)
> ```

**JSON Body parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| path | string | y | Path to the Bijection function formatted as a string as defined [here](https://docs.bijection.com/functions/queries.md#query-names). |
| args | object | y | Named argument object to pass to the Bijection function. |
| format | string | n | Output format for values. Valid values: \[`json`] |

Work outside the deployment is a [target](https://docs.bijection.com/functions/effects.md): a mutation
submits it, and its continuation records the result. There is no endpoint that
calls a target directly.

Replies carry no log lines. A function's lines are [`sys.logs`](https://docs.bijection.com/operate/observability/logs) facts: read them
with `bijection list sys.logs` or `ctx.list(sys.logs...)` under clearance.

**Result JSON on success**

| Field Name | Type | Description |
| - | - | - |
| status | string | "success" |
| value | object | Result of the Bijection function in the requested format. |

**Result JSON on error**

| Field Name | Type | Description |
| - | - | - |
| status | string | "error" |
| errorMessage | string | The error message. |
| errorData | object | Error data within an [application error](https://docs.bijection.com/functions/errors.md) if it was thrown. |

`/api/query` and `/api/mutation` answer an error with status 200.

### POST `/api/run/{functionIdentifier}`

This HTTP endpoint allows you to call arbitrary Bijection function types with the
path in the request URL and get the result as a value. The function identifier
is formatted as a string as defined
[here](https://docs.bijection.com/functions/queries.md#query-names) with a `/` replacing the `:`.

You can find your backend deployment URL on the console
[Settings](https://docs.bijection.com/operate/installations) page, then the API URL will be
`<BIJECTION_URL>/api/run/{functionIdentifier}` etc., for example:

> [tab] Shell
>
> ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> curl https://acoustic-panther-728.bijection.cloud/api/run/messages/list \
>    -d '{"args": {}, "format": "json"}' \
>    -H "Content-Type: application/json"
> ```

> [tab] NodeJS
>
> ```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> const url = "https://acoustic-panther-728.bijection.cloud/api/run/messages/list";
> const request = { format: "json" };
>
> const response = fetch(url, {
>   method: "POST",
>   headers: {
>     "Content-Type": "application/json",
>   },
>   body: JSON.stringify(request),
> });
> ```

> [tab] Python
>
> ```py theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> import requests
>
> url = "https://acoustic-panther-728.bijection.cloud/api/run/messages/list"
> headers = {"accept": "application/json"}
> body = {"args": {}, "format": "json"}
>
> response = requests.post(url, headers=headers, json=body)
> ```

**JSON Body parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| args | object | y | Named argument object to pass to the Bijection function. |
| format | string | n | Output format for values. Defaults to `json`. Valid values: \[`json`] |

**Result JSON on success**

| Field Name | Type | Description |
| - | - | - |
| status | string | "success" |
| value | object | Result of the Bijection function in the requested format. |

**Result JSON on error**

| Field Name | Type | Description |
| - | - | - |
| status | string | "error" |
| errorMessage | string | The error message. |
| errorData | object | Error data within an [application error](https://docs.bijection.com/functions/errors.md) if it was thrown. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.