# Preview a layer before adding it

`POST https://evohub.io/api/v1/schedules/{id}/layers/preview`

Part of the [On-Call API](https://docs.evohub.io/oncall.md) reference · operationId `previewScheduleLayer`.

The next six turns a layer would give, worked out on the schedule's
clock, without storing anything. Send the layer as you would to
`POST /api/v1/schedules/{id}/layers`, plus `user_ids`, the members in
rota order. `name` may be left out. With no `user_ids` the handovers are
still returned, each with an empty `user_id`. The turns start from
`rotation_start` when it lies in the future, otherwise from now. Each
turn runs from handover to handover; it is not cut to the shift window.

A schedule that belongs to a team is visible only to callers in that team (and
to administrators acting in person); others get 404, as if it did not exist.

**Permission (API-key scope):** `oncall:schedule:write`.

## Authorization

Any one of:

- `bearerAuth` (oncall:schedule:write)
- `apiKeyHeader` (oncall:schedule:write)

Where:

- `bearerAuth`: HTTP Bearer — An EvoHub API key (`evohub_…`) as a bearer token.
- `apiKeyHeader`: API key in the header `X-API-Key` — An EvoHub API key (`evohub_…`).

## Path parameters

- `id` (string, required, example `5b1c7d2e-8f3a-4b9c-a0d1-e2f3a4b5c6d7`): The schedule's id.

## Request body (required)

Content type: `application/json`

Type: `ScheduleLayerSpec`

A whole layer as a form sends it — its settings and its members in rota order.

- `name` (string)
- `priority` (integer)
- `rotation_type` (RotationType, one of `daily`, `weekly`, `custom`)
- `rotation_unit` (string, one of `day`, `hour`): What `handoff_day` counts on a `custom` rotation; `day` when left out.
- `rotation_start` (string (date-time))
- `handoff_day` (integer): For a `custom` rotation, the days (1–365) or hours (1–168) each turn lasts.
- `handoff_weekday` (integer, min 0, max 6): The weekday a `weekly` rotation hands over on, 0 (Sunday) to 6. Left out, it hands over on the weekday `rotation_start` falls on.
- `handoff_time` (string): `HH:MM` on the schedule's clock.
- `restrict_to_weekdays` (array of integer)
- `restrict_start_time` (string)
- `restrict_end_time` (string)
- `user_ids` (array of string): The members in rota order, each once.

## Responses

### 200 — The next six turns.

Content type: `application/json`

Type: `object`

- `data` (object, required)
  - `turns` (array of ScheduleTurn, required)
    - `layer_id` (string): The layer giving the turn (`preview` for a layer that is not stored yet).
    - `user_id` (string): Who holds the turn; empty in a preview with no members.
    - `start` (string (date-time))
    - `end` (string (date-time))
- `success` (boolean, required, value `true`)

### 400 — The body is not JSON (`INVALID_BODY`), or a field is invalid as on create, or `user_ids` names someone twice or holds an empty id (`VALIDATION_FAILED`).

Content type: `application/json`

Type: `ValidationError`

- `error` (object, required)
  - `code` (string, required, value `VALIDATION_FAILED`)
  - `message` (string, required)
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.
  - `details` (array of object, required)
    - `field` (string)
    - `message` (string)

### 401 — No API key was sent, or it is unknown, revoked or expired (`UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.

### 403 — The key lacks the scope this endpoint needs (`FORBIDDEN`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.

### 404 — No schedule with this id in your organization (`NOT_FOUND`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.

### 429 — Too many requests (`RATE_LIMITED`). Wait `Retry-After` seconds.

Headers:

- `Retry-After` (integer): Seconds to wait.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.

### 500 — Something went wrong on EvoHub's side (`INTERNAL_ERROR`). Retry later.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.
  - `request_id` (string): The request's `X-Request-ID`. Quote it to support.

## Example request

```bash
curl -X POST 'https://evohub.io/api/v1/schedules/5b1c7d2e-8f3a-4b9c-a0d1-e2f3a4b5c6d7/layers/preview' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "user_ids": [
    "0b8e6c1a-2f4d-4e9b-8a7c-3d5e6f708192",
    "9a7b5c3d-1e2f-4a6b-8c0d-2e4f6a8b0c1d"
  ],
  "handoff_time": "09:00",
  "rotation_type": "weekly",
  "rotation_start": "2026-10-19T06:00:00Z",
  "handoff_weekday": 1
}'
```
