# Data API overview

Source: https://cubibase.com/docs/data-api

Also available: [Markdown version](https://cubibase.com/docs/data-api.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

Every exposed table is served at /rest/v1/{table} on your project host. Two headers on every request: the publishable key and the user’s JWT.

## The request shape

| Piece | Value | Purpose |
| --- | --- | --- |
| Host | `https://{slug}.api.cubibase.com` | Selects the project |
| Path | `/rest/v1/{table}` | Selects the exposed table |
| `apikey` header | Publishable key (`cb_pub_…`) | Identifies the project credential |
| `Authorization` header | `Bearer <USER_JWT>` | Identifies the end user |

**Request**

```http
GET https://example-project.api.cubibase.com/rest/v1/customers?plan=eq.pro&order=name.asc&limit=20
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <USER_JWT>
```

**200 · response**

```json
{
  "data": [
    {
      "id": "8c1a0b2e-7d44-4a11-9c31-0b51a6e4d901",
      "name": "Mina Cho",
      "email": "mina@example.com",
      "plan": "pro",
      "owner_id": "user_mina"
    },
    {
      "id": "44ab91c3-0e55-4d72-b018-6f2c8a91bb70",
      "name": "Priya Shah",
      "email": "priya@example.org",
      "plan": "pro",
      "owner_id": "user_priya"
    }
  ]
}
```

> **note**: The publishable key alone is not enough. A request without a bearer token fails with `401 missing_end_user_token`, even with a valid key.

## Response envelope

Every successful response wraps its payload in a `data` field. Lists return an array; single rows and writes return one object.

| Call | Status | `data` contains |
| --- | --- | --- |
| `GET /rest/v1/{table}` | `200` | An array of rows (possibly empty) |
| `GET /rest/v1/{table}/{id}` | `200` | One row object |
| `POST /rest/v1/{table}` | `201` | The inserted row, all columns |
| `PATCH /rest/v1/{table}/{id}` | `200` | The updated row, all columns |
| `DELETE /rest/v1/{table}/{id}` | `200` | The deleted row, all columns |
| `POST /rest/v1/rpc/{function}` | `200` | The function result: a value, an object, or an array |

## Errors

Errors are JSON objects with a stable `code`, a human `message`, and a `requestId` you can match against the project logs.

**401 · missing bearer token**

```json
{
  "error": {
    "code": "missing_end_user_token",
    "message": "An end-user bearer token is required",
    "requestId": "req_example"
  }
}
```

| Status | Code | Meaning |
| --- | --- | --- |
| `401` | `missing_api_key` / `invalid_api_key` | The publishable key is absent or wrong |
| `401` | `missing_end_user_token` / `invalid_token` | The bearer JWT is absent or fails verification |
| `404` | `not_found` | Unknown table, unexposed table, or missing row |
| `405` | `method_not_allowed` | That operation is not exposed for the table |

## What the API does not do

- No joins or nested resources: one table request addresses one table. Logic that spans tables belongs in a function, called over RPC.
- No bulk writes: `POST` inserts one row; `PATCH` and `DELETE` address one primary key.
- No arbitrary SQL from the application — the SQL editor is a Console tool. Functions you write and grant are the supported way to run custom logic.
- Tables with composite primary keys are not served by the row-by-id routes.

## Additional resources

- [Querying rows](https://cubibase.com/docs/data-api/querying) Filters, select, order, limit, offset.
- [Writing rows](https://cubibase.com/docs/data-api/writing) Insert, update, delete, and constraint errors.
- [Calling functions (RPC)](https://cubibase.com/docs/data-api/rpc) Run your SQL functions from the app.
- [Error codes](https://cubibase.com/docs/reference/errors) The full list, with causes and fixes.
