# The data API

Rows of your project's tables as JSON over HTTPS. Row-level security decides which rows the caller gets; the API never widens it.

```
https://api.rezincore.com/v1/data/<table>
```

Every request carries the project key in `apikey`, and normally a user's token in `Authorization: Bearer <token>`. See [who a request acts for](https://rezincore.com/docs/getting-started/concepts.md#keys-and-who-a-request-acts-for).

The examples use:

```
export API=https://api.rezincore.com
export KEY=rzc_pub_your_publishable_key
export TOKEN=the_signed_in_users_token
```

## Read rows

```
GET /v1/data/<table>
```

```
curl -s "$API/v1/data/notes?pinned=eq.true&order=created_at.desc&limit=20" \
  -H "apikey: $KEY" -H "authorization: Bearer $TOKEN"
```

```json
{ "rows": [ { "id": "…", "title": "Hello", "pinned": true, "created_at": "2026-11-26T15:04:05.000Z" } ] }
```

### Filters

A filter is a query parameter: `column=operator.value`. Several filters must all match.

| Operator | Meaning | Example |
|---|---|---|
| `eq` | equals | `status=eq.open` |
| `neq` | does not equal | `status=neq.closed` |
| `gt`, `gte` | greater than, or equal | `amount=gte.100` |
| `lt`, `lte` | less than, or equal | `created_at=lt.2026-12-01` |
| `like` | matches a pattern, case-sensitive; `*` is the wildcard | `title=like.Report*` |
| `ilike` | the same, ignoring case | `title=ilike.*invoice*` |
| `in` | is one of a list | `status=in.(open,waiting)` |
| `is` | is or is not null | `closed_at=is.null`, `closed_at=is.notnull` |

The same column can be filtered twice: `amount=gte.100&amount=lt.500`.

### Other options

| Parameter | Meaning | Default |
|---|---|---|
| `select=a,b` | Only these columns | all columns |
| `order=a.asc,b.desc` | Sort order | no order promised |
| `limit` | How many rows, 1 to 1000 | 100 |
| `offset` | How many rows to skip | 0 |

For stable paging, always send `order` with a column that does not repeat, such as the primary key.

`select`, `order`, `limit` and `offset` are reserved words here: a column with one of those names cannot be used as a filter.

## Add rows

```
POST /v1/data/<table>
```

Send one row as a JSON object, or up to 500 rows as a list. The answer is `201` with the rows as stored, defaults included.

```
curl -s $API/v1/data/notes -H "apikey: $KEY" -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" -d '{"title":"Hello"}'
```

```json
{ "rows": [ { "id": "…", "organization_id": "…", "title": "Hello", "pinned": false } ] }
```

If the table has an `organization_id` column and the row does not say, it is set to the caller's organization. Naming another organization is refused by your policy's "with check".

A value that is a JSON object or list is stored as JSON, for a `jsonb` column.

## Change rows

```
PATCH /v1/data/<table>?<filter>
```

Send the values to change as a JSON object. **A filter is required**: without one the answer is `400 filter_required`. The answer has the changed rows.

```
curl -s -X PATCH "$API/v1/data/notes?id=eq.$ID" -H "apikey: $KEY" -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" -d '{"pinned":true}'
```

```json
{ "rows": [ { "id": "…", "title": "Hello", "pinned": true } ] }
```

If no row matches, or the caller may not see the matching rows, `rows` is empty. That is not an error.

## Delete rows

```
DELETE /v1/data/<table>?<filter>
```

**A filter is required.** The answer says how many rows went.

```
curl -s -X DELETE "$API/v1/data/notes?id=eq.$ID" -H "apikey: $KEY" -H "authorization: Bearer $TOKEN"
```

```json
{ "deleted": 1 }
```

## From your own server, without a user

With a **secret key** and no token, name the organization to act for:

```
curl -s "$API/v1/data/notes?limit=50" \
  -H "apikey: $SECRET_KEY" -H "x-organization-id: 0d9c8b7a-6f5e-4d3c-8b2a-1f0e9d8c7b6a"
```

Row-level security still applies. `core.app_org()` is that organization and `core.app_user()` is null, so a policy that compares a column with `core.app_user()` lets nothing through.

## What the API will not do

- Reach a table outside the project, or a table the application's role has not been allowed to touch (`403 not_allowed`).
- Join tables, count, or aggregate. Make a view or a function in SQL for that, or do it in your application.
- Change or delete without a filter.
- Echo your data in an error. A refusal says what kind of thing went wrong and names the constraint or column, never the values.

## Errors you will meet

| Status | Code | When |
|---|---|---|
| 400 | `bad_request` | An unknown column, a malformed filter, a wrong type, a missing required value |
| 400 | `filter_required` | `PATCH` or `DELETE` without a filter |
| 401 | `sign_in_required` | A publishable key with no token |
| 401 | `signed_out` | The token has ended |
| 403 | `not_allowed` | The application's role may not do that to this table, or the row is outside what the caller may write |
| 404 | `not_found` | No such table |
| 409 | `conflict` | A unique value already exists, or a linked row does not |
| 408 | `timeout` | The request took too long |

The full list is on [Errors](https://rezincore.com/docs/reference/errors.md). Every call is on the audit trail: who, which table, how many rows, which fields were changed. Never the values.
