# Collections

> A site’s own lists (menu, rooms, team, events), their entries and where they come from. 14 endpoints in the Unvop API.

A site’s own lists (menu, rooms, team, events), their entries and where they come from.

## List collections

`GET /v1/sites/{siteId}/collections`

Scope: `content:read`.

The site’s collections (menu, rooms, team, events…) with their fields and entry counts.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `key` (string, required): The handle used in URLs, like "menu" or "dive-sites".
  - `name` (string, required)
  - `singular` (string)
  - `fields` (array, required)
  - `settings` (object, required)
  - `entryCount` (integer)
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create a collection

`POST /v1/sites/{siteId}/collections`

Scope: `content:write`, as a site owner or admin.

Add a collection, from a preset or with your own fields. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `name` (string): (up to 80 characters)
- `singular` (string): What one entry is called, like "Dish". (up to 80 characters)
- `key` (string): The handle in URLs. Made from the name when left out. (up to 60 characters)
- `preset` (string): Start from a preset (menu, team, events, rooms…): its fields and settings. (up to 60 characters)
- `fields` (array): Fields: { key, label, type, required?, options? }. Types include text, richText, number, price, image, date, select, boolean, url, email and reference. (up to 200 items)
- `settings` (object): Sorting, entry pages (basePath), labels.

### Response 201

- `id` (string, required)
- `key` (string, required): The handle used in URLs, like "menu" or "dive-sites".
- `name` (string, required)
- `singular` (string)
- `fields` (array, required)
- `settings` (object, required)
- `entryCount` (integer)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Team",
    "fields": [
      {
        "key": "role",
        "label": "Role",
        "type": "text"
      }
    ]
  }'
```

## Get a collection

`GET /v1/sites/{siteId}/collections/{key}`

Scope: `content:read`.

One collection with its fields and settings.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Response 200

- `id` (string, required)
- `key` (string, required): The handle used in URLs, like "menu" or "dive-sites".
- `name` (string, required)
- `singular` (string)
- `fields` (array, required)
- `settings` (object, required)
- `entryCount` (integer)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections/team \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a collection

`PUT /v1/sites/{siteId}/collections/{key}`

Scope: `content:write`, as a site owner or admin.

Change a collection’s name, fields or settings. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Request body (JSON)

- `name` (string): (up to 80 characters)
- `singular` (string): What one entry is called, like "Dish". (up to 80 characters)
- `key` (string): The handle in URLs. Made from the name when left out. (up to 60 characters)
- `fields` (array): Fields: { key, label, type, required?, options? }. Types include text, richText, number, price, image, date, select, boolean, url, email and reference. (up to 200 items)
- `settings` (object): Sorting, entry pages (basePath), labels.

### Response 200

- `id` (string, required)
- `key` (string, required): The handle used in URLs, like "menu" or "dive-sites".
- `name` (string, required)
- `singular` (string)
- `fields` (array, required)
- `settings` (object, required)
- `entryCount` (integer)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PUT https://api.unvop.com/v1/sites/site_123/collections/team \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "singular": "Member"
  }'
```

## Delete a collection

`DELETE /v1/sites/{siteId}/collections/{key}`

Scope: `content:write`, as a site owner or admin.

Delete a collection and all its entries. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123/collections/team \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List entries

`GET /v1/sites/{siteId}/collections/{key}/entries`

Scope: `content:read`.

A collection’s entries in their order. Filter by status or search with q.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Query parameters

- `limit` (integer): How many to return (default 50). (min 1; max 200)
- `cursor` (string): The cursor from the previous page.
- `status` (string): One of `draft`, `published`.
- `q` (string): Search the slug and values.
- `offset` (integer): Kept for older clients; prefer cursor. (min 0)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `slug` (string, required)
  - `status` (string, required): One of `draft`, `published`.
  - `data` (object, required): Values keyed by field key.
  - `position` (number)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `updatedAt` (string, required): An ISO 8601 timestamp.
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections/team/entries \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Add an entry

`POST /v1/sites/{siteId}/collections/{key}/entries`

Scope: `content:write`.

Add an entry. Values are checked against the collection’s fields; errors come back in details.fields keyed data.<field>. Workflows listening for new entries run.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `slug` (string): Made from the title when left out. (up to 200 characters)
- `data` (object): Values keyed by field key.
- `status` (string): Published entries go live at once. One of `draft`, `published`.

### Response 201

- `id` (string, required)
- `slug` (string, required)
- `status` (string, required): One of `draft`, `published`.
- `data` (object, required): Values keyed by field key.
- `position` (number)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `updatedAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `409`: It conflicts with the current state.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

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

## Get an entry

`GET /v1/sites/{siteId}/collections/{key}/entries/{slug}`

Scope: `content:read`.

One entry, by its slug (or id).

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)
- `slug` (string, required)

### Response 200

- `id` (string, required)
- `slug` (string, required)
- `status` (string, required): One of `draft`, `published`.
- `data` (object, required): Values keyed by field key.
- `position` (number)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `updatedAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections/team/entries/ana \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change an entry

`PUT /v1/sites/{siteId}/collections/{key}/entries/{slug}`

Scope: `content:write`.

Change an entry’s values, slug or status. Values you send replace the stored ones for those fields.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)
- `slug` (string, required)

### Request body (JSON)

- `slug` (string): Made from the title when left out. (up to 200 characters)
- `data` (object): Values keyed by field key.
- `status` (string): Published entries go live at once. One of `draft`, `published`.

### Response 200

- `id` (string, required)
- `slug` (string, required)
- `status` (string, required): One of `draft`, `published`.
- `data` (object, required): Values keyed by field key.
- `position` (number)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `updatedAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `409`: It conflicts with the current state.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

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

## Delete an entry

`DELETE /v1/sites/{siteId}/collections/{key}/entries/{slug}`

Scope: `content:write`.

Delete an entry. It leaves the live site at once.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)
- `slug` (string, required)

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `409`: It conflicts with the current state.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123/collections/team/entries/ana \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Get a collection’s source

`GET /v1/sites/{siteId}/collections/{key}/source`

Scope: `connections:read`.

Where the entries come from: typed in (manual), synced from a connection every 15 minutes (sync), or fetched while the page renders (live). Also whether the collection is published at /api/data/{key}.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Response 200

- `source` (object, required)
  - `mode` (string, required): One of `manual`, `sync`, `live`.
  - `connectionId` (string, nullable)
- `api` (object, required)
  - `enabled` (boolean, required)
  - `access` (string, required): One of `public`, `key`.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections/team/source \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a collection’s source

`PUT /v1/sites/{siteId}/collections/{key}/source`

Scope: `connections:write`, as a site owner or admin.

Point a collection at a connection (sync or live), map the answer’s fields to the collection’s, or set it back to manual. A collection that starts syncing is pulled at once. Also turns its public data API on or off. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Request body (JSON)

- `source` (object)
  - `mode` (string): One of `manual`, `sync`, `live`.
  - `connectionId` (string, nullable)
  - `path` (string): Added to the connection’s base URL.
  - `itemsPath` (string): Where the list is in the answer, as a dot path ("" for the top level).
  - `mapping` (map of string): Field key to a dot path in each item.
  - `idPath` (string)
  - `everyMinutes` (integer)
  - `ttlMinutes` (integer)
- `api` (object)
  - `enabled` (boolean)
  - `access` (string): One of `public`, `key`.

### Response 200

- `source` (object, required)
  - `mode` (string, required): One of `manual`, `sync`, `live`.
  - `connectionId` (string, nullable)
- `api` (object, required)
  - `enabled` (boolean, required)
  - `access` (string, required): One of `public`, `key`.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PUT https://api.unvop.com/v1/sites/site_123/collections/team/source \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "source": {
      "mode": "manual",
      "connectionId": "conn_123",
      "path": "/menu",
      "mapping": {},
      "everyMinutes": 1,
      "ttlMinutes": 1
    },
    "api": {
      "enabled": true,
      "access": "public"
    }
  }'
```

## Preview a source

`POST /v1/sites/{siteId}/collections/{key}/source/preview`

Scope: `connections:write`, as a site owner or admin.

Ask a connection for data at a path and see the lists in the answer, the first item’s values and a suggested field mapping, without saving anything.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Request body (JSON)

- `connectionId` (string, required)
- `path` (string)
- `itemsPath` (string)

### Response 200

- `probe` (object, required): What a connection answered.
  - `ok` (boolean, required)
  - `status` (number)
  - `sample` (any)
  - `error` (string)
- `candidates` (array, required)
- `itemsPath` (string, required, nullable)
- `count` (number, required)
- `mapping` (map of string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/collections/team/source/preview \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connectionId": "conn_123"
  }'
```

## Sync now

`POST /v1/sites/{siteId}/collections/{key}/source/sync`

Scope: `connections:write`, as a site owner or admin.

Pull a synced collection from its connection now instead of waiting for the next 15-minute sync.

### Path parameters

- `siteId` (string, required): The site’s id.
- `key` (string, required)

### Response 200

- `source` (object, required)
  - `mode` (string, required): One of `manual`, `sync`, `live`.
  - `connectionId` (string, nullable)
- `api` (object, required)
  - `enabled` (boolean, required)
  - `access` (string, required): One of `public`, `key`.
- `sync` (any, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X POST https://api.unvop.com/v1/sites/site_123/collections/team/source/sync \
  -H "Authorization: Bearer $UNVOP_KEY"
```
