# Scheduled operations

Scheduled operations let you pre-program a start and stop time for any Live API resource. The operation schedules startup at `startTime` and shutdown at `endTime`. These transitions are asynchronous: monitor the live resource's `status.state` to confirm that it has reached `Running` or `Stopped`.

The only supported operation type is `MediaKind.ScheduledOperation.StartStop`. Each operation is a named resource scoped to its parent live resource.

## Create a scheduled operation

Set the operation name in the URL path. `startTime` and `endTime` are both required and must be ISO 8601 UTC datetime strings. `correlationData` is a required field for user-defined metadata; pass an empty object if you have no metadata to attach.

```bash
curl -X PUT "https://app.mk.io/api/v1/projects/<PROJECT_NAME>/live/liveEvents/my-event/scheduledOperations/broadcast-window" \
  -H "Authorization: Bearer <YOUR_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "spec": {
      "type": "MediaKind.ScheduledOperation.StartStop",
      "startTime": "<START_TIME_UTC>",
      "endTime": "<END_TIME_UTC>",
      "correlationData": {
        "eventId": "summer-finale"
      }
    }
  }'
```

The same endpoint works for `liveChannels`, `liveEvents`, `staticMultiviewChannels`, and `staticMultiviewEvents`. Substitute the resource type and resource name in the path.

Before creating the operation, retrieve the live resource and each referenced asset, source or content resource, and config. Repeat this dependency check shortly before execution. Confirm that all references are valid before the scheduled broadcast.

## List scheduled operations

```bash
curl -X GET "https://app.mk.io/api/v1/projects/<PROJECT_NAME>/live/liveEvents/my-event/scheduledOperations" \
  -H "Authorization: Bearer <YOUR_TOKEN>"
```

## Get a scheduled operation

```bash
curl -X GET "https://app.mk.io/api/v1/projects/<PROJECT_NAME>/live/liveEvents/my-event/scheduledOperations/broadcast-window" \
  -H "Authorization: Bearer <YOUR_TOKEN>"
```

The response includes `spec` with the scheduled times and `status` with the current state of the operation.

## Update a scheduled operation

PUT replaces the full operation spec. To change only the start or end time, issue a new PUT with the updated times.

```bash
curl -X PUT "https://app.mk.io/api/v1/projects/<PROJECT_NAME>/live/liveEvents/my-event/scheduledOperations/broadcast-window" \
  -H "Authorization: Bearer <YOUR_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "spec": {
      "type": "MediaKind.ScheduledOperation.StartStop",
      "startTime": "<UPDATED_START_TIME_UTC>",
      "endTime": "<UPDATED_END_TIME_UTC>",
      "correlationData": {
        "eventId": "summer-finale"
      }
    }
  }'
```

## Delete a scheduled operation

```bash
curl -X DELETE "https://app.mk.io/api/v1/projects/<PROJECT_NAME>/live/liveEvents/my-event/scheduledOperations/broadcast-window" \
  -H "Authorization: Bearer <YOUR_TOKEN>"
```

If the operation does not exist, the API returns `204`.

## Usage notes

- A single resource can have multiple scheduled operations with non-overlapping time windows.
- The resource must exist before you create a scheduled operation on it.
- A scheduled state change does not provide media. Coordinate the contribution encoder to begin at the scheduled start or when the resource enters `Starting`.
- `spec.correlationData` is returned with the scheduled operation and can be used to correlate it with external scheduling systems.
- All times are in UTC. Confirm your `startTime` and `endTime` values before creating operations for production broadcasts.
