# Change a layer from a later moment

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

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

Changes a layer — its settings and its members — from a moment you
choose, so the turn under way is not cut short unless you ask for that.
Send the whole layer as it should be (the fields of
`POST /api/v1/schedules/{id}/layers`, `name` and `rotation_type`
required), `user_ids` with every member in rota order, and when the
change takes over:

- `effective: now` — at once.
- `effective: after_current_shift` (the default) — when the current turn ends.
- `effective: after_full_rotation` — when the current pass through the list ends.
- `effective: at` with `at`, an RFC 3339 instant that is not in the past.

The layer as it was runs until that moment, and a revised copy runs from
it: the response's `layer` is the copy, with `active_from` set and
`replaces_layer_id` pointing at the original. Unless `restart` is
`true`, the person who would hold the rota at that moment keeps it,
wherever they now sit in the list; with `restart: true` the new list
begins at its first member. Only the layer in effect now can be changed
this way; a change already waiting on it is replaced by the new one.
Anyone added to the rota must be a member of the organization
who can respond to alerts.

**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.
- `layerID` (string, required, example `7c3d9e1f-2a4b-4c6d-8e0f-1a2b3c4d5e6f`): The layer's id. It must belong to the schedule in the path.

## Request body (required)

Content type: `application/json`

Type: `ScheduleLayerRevision`

A layer as it should be, and when that takes over. `name` and `rotation_type` are required. `rotation_start` is checked but not used; the changed layer starts at the moment the change takes over.

- `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.
- `effective` (string, one of `now`, `after_current_shift`, `after_full_rotation`, `at`, default `after_current_shift`)
- `at` (string (date-time)): With `effective` `at`, the moment the change takes over; not in the past.
- `restart` (boolean, default `false`): Begin the new list at its first member instead of keeping the current holder.

## Responses

### 201 — When the change takes over, and the layer that runs from then.

Content type: `application/json`

Type: `object`

- `data` (object, required)
  - `effective_at` (string (date-time), required)
  - `layer` (ScheduleLayer, required)
    - `id` (string)
    - `schedule_id` (string)
    - `name` (string)
    - `priority` (integer): Lower numbers win. When several layers have someone on call, the layer with the smallest `priority` decides who is paged.
    - `rotation_type` (RotationType, one of `daily`, `weekly`, `custom`)
    - `rotation_start` (string (date-time)): When the rota's first turn started.
    - `handoff_day` (integer): For a `custom` rotation, the days (or, with `rotation_unit` `hour`, the hours) each turn lasts. Daily and weekly rotations ignore it.
    - `handoff_time` (string): `HH:MM` of the handover.
    - `rotation_unit` (string): What `handoff_day` counts on a `custom` rotation, `day` or `hour`; empty means `day`.
    - `handoff_weekday` (integer | null): The weekday a `weekly` rotation hands over on, 0 (Sunday) to 6; `null` is the weekday `rotation_start` falls on.
    - `restrict_to_weekdays` (array of integer)
    - `restrict_start_time` (string): `HH:MM`
    - `restrict_end_time` (string): `HH:MM`
    - `rotations` (array of ScheduleRotation)
      - `id` (string)
      - `layer_id` (string)
      - `user_id` (string)
      - `position` (integer): 0-based place in the rota.
      - `created_at` (string (date-time))
    - `active_from` (string (date-time)): Set on a layer that replaces another from a later moment; it applies from then.
    - `active_until` (string (date-time)): Set on a layer that a change replaces from a later moment; it applies until then.
    - `replaces_layer_id` (string): On a changed copy, the layer it replaces.
    - `created_at` (string (date-time))
    - `updated_at` (string (date-time))
- `success` (boolean, required, value `true`)

### 400 — The body is not JSON (`INVALID_BODY`); a layer field is invalid as on create, `user_ids` names someone twice, `effective` is not one of the four values, `at` is missing or not RFC 3339 when `effective` is `at`, or `at` is in the past (`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 such schedule, or no such layer on it (`NOT_FOUND`), or someone added in `user_ids` is not a member of the organization (`NOT_A_MEMBER`).

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.

### 409 — The layer has ended or has not started yet (`LAYER_NOT_IN_EFFECT`); change the layer in effect instead.

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.

### 422 — The person cannot respond to alerts: they do not hold `oncall:alert:respond` (`CANNOT_RESPOND`).

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.

### 503 — Whether the person may be paged could not be checked right now; nothing was changed (`MEMBER_CHECK_UNAVAILABLE`). Retry shortly.

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/7c3d9e1f-2a4b-4c6d-8e0f-1a2b3c4d5e6f/revise' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "name": "Primary",
  "priority": 1,
  "user_ids": [
    "0b8e6c1a-2f4d-4e9b-8a7c-3d5e6f708192",
    "9a7b5c3d-1e2f-4a6b-8c0d-2e4f6a8b0c1d",
    "3c5e7a9b-1d2f-4b6c-8e0a-4f6b8d0e2a3c"
  ],
  "effective": "after_current_shift",
  "handoff_time": "09:00",
  "rotation_type": "weekly",
  "handoff_weekday": 1
}'
```
