
# Collections and live data

A collection is one of a site's own lists: a menu, rooms, courses, a team, events. It has **fields** (title, price, image, date and so on) and **entries**. Pages show a collection with a collection list block, and with entry pages on, each entry gets its own page at an address like `/team/ana`.

A collection is addressed by its `key` (like `team`), an entry by its `slug` (or id).

## Create a collection

Start from a preset (`menu`, `team`, `events`, `rooms`…) or give your own fields. Creating, changing and deleting collections is for owners and admins.

```json title="POST /sites/{siteId}/collections"
{
  "name": "Team",
  "fields": [
    { "key": "role", "label": "Role", "type": "text" },
    { "key": "photo", "label": "Photo", "type": "image" }
  ]
}
```

Field types include `text`, `richText`, `number`, `price`, `image`, `date`, `select`, `boolean`, `url`, `email` and `reference`. A field is `{ key, label, type, required?, options? }`.

## Add and change entries

```sh
curl https://api.unvop.com/v1/sites/site_…/collections/team/entries \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "data": { "title": "Ana", "role": "Guide" }, "status": "published" }'
```

Values are checked against the collection's fields, and problems come back in `details.fields` keyed `data.<field>`. A published entry is on the live site straight away, and workflows listening for new entries run.

- `GET …/collections/{key}/entries` lists entries in their order. Filter with `status`, search with `q`, page with `limit` and `cursor`.
- `PUT …/entries/{slug}` changes an entry: values you send replace the stored ones for those fields.
- `DELETE …/entries/{slug}` deletes one, and it leaves the live site at once.

## Where entries come from

Every collection has a **source**. A section never cares which one: it shows the list either way.

| Mode | Entries are | Edited in the dashboard |
|---|---|---|
| `manual` | typed in, in the dashboard or through the API | yes |
| `sync` | pulled from a [connection](https://developers.unvop.com/guides/connections.md) every 15 minutes and stored | no: the source is the truth |
| `live` | fetched from the connection while the page renders, cached for `ttlMinutes`, never stored | no |

Live collections still render plain static HTML: no client JavaScript runs on the visitor's side.

### Point a collection at a connection

First see what the connection answers. `POST …/collections/{key}/source/preview` asks it for data at a path and returns the lists it found, the first item's values and a suggested mapping, without saving anything:

```json title="POST …/collections/menu/source/preview"
{ "connectionId": "con_…", "path": "/menu" }
```

Then save the source. `mapping` maps each field key to a dot path in each item, and `itemsPath` says where the list is in the answer (`""` for the top level):

```json title="PUT …/collections/menu/source"
{
  "source": {
    "mode": "sync",
    "connectionId": "con_…",
    "path": "/menu",
    "itemsPath": "data.items",
    "mapping": { "title": "name", "price": "price.amount" }
  }
}
```

A collection that starts syncing is pulled at once. `POST …/source/sync` pulls it again now instead of waiting for the next sync. Synced and live entries are read-only: writing one gets `409 conflict`. Changing sources needs `connections:write` and an owner or admin.

## Publish a collection

Turn a collection's data API on and its published entries are served as JSON on the site's own address:

```json title="PUT …/collections/menu/source"
{ "api": { "enabled": true, "access": "public" } }
```

```sh
curl https://harbour-bakery.unvop.dev/api/data/menu
```

```json
{
  "collection": { "key": "menu", "name": "Menu", "singular": "Dish", "fields": [ … ] },
  "entries": [
    { "id": "ent_…", "slug": "sourdough", "data": { "title": "Sourdough", "price": 650 }, "updatedAt": "2026-11-20T08:00:00Z" }
  ],
  "updatedAt": "2026-11-20T08:00:00Z"
}
```

With `access: "public"` anyone may read it, with CORS open, cached for a minute. With `access: "key"`, callers send `Authorization: Bearer <key>`: a site key of this site or a platform key with `content:read`. Account keys aren't accepted here. A live collection answers its current list.
