> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automaticrostering.visma.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Shift templates

> Generate eligible shifts from time demand instead of defining every shift in advance.

Shift templates let the solver generate shifts that fit your time demand. Rather
than listing every possible shift in `shifts`, define the start and end windows,
duration range, and work that a generated shift can contain.

<Info>
  Shift templates are available only for `TIME_DEMAND` rosters. Set `context.demandType` to `TIME_DEMAND`, provide the
  required `timeSlots` and time demands, then add templates under `extensions.shiftTemplates`.
</Info>

## Send shift templates in a roster request

Each template needs an `id`, a start window, an end window, a duration range,
and at least one interval. The interval describes the work in the generated
shift. In this example, the solver can generate a day shift that starts between
08:00 and 09:00, ends between 16:00 and 17:00, and lasts seven to eight hours.

```json title="Add a shift template to a TIME_DEMAND request" theme={null}
{
  "context": {
    "demandType": "TIME_DEMAND"
  },
  "extensions": {
    "shiftTemplates": [
      {
        "id": "day",
        "labels": ["day"],
        "start": {
          "window": {
            "start": "08:00",
            "end": "09:00"
          }
        },
        "end": {
          "window": {
            "start": "16:00",
            "end": "17:00"
          }
        },
        "duration": {
          "min": 420,
          "max": 480
        },
        "intervals": [
          {
            "workload": {
              "category": "service"
            }
          }
        ]
      }
    ]
  }
}
```

The solver considers start-time and duration combinations whose resulting end
time falls inside the end window. A template's labels and attribute
requirements are copied to the generated shifts.

## Read generated template shifts from the result

Only template shifts assigned in the created roster are returned. Find their
definitions in `roster.extensions.templateShifts`; assignments that use them
refer to the same generated shift `id`.

Each generated shift includes its concrete intervals and the `shiftTemplateId`
that links it back to the template you sent. Generated IDs use the reserved
`template:` namespace and are numbered separately for each template.

```json title="Template shifts in a roster result" theme={null}
{
  "roster": {
    "employeeRosters": [
      {
        "employeeId": "employee-1",
        "assignments": [
          {
            "shiftId": "template:day-1",
            "day": {
              "dayIndex": 0
            }
          }
        ]
      }
    ],
    "extensions": {
      "templateShifts": [
        {
          "id": "template:day-1",
          "shiftTemplateId": "day",
          "labels": ["day"],
          "intervals": [
            {
              "startTime": "08:00",
              "endTime": "16:00",
              "workload": {
                "category": "service"
              }
            }
          ]
        }
      ]
    }
  }
}
```

<Note>
  Shift templates will gain more configuration options in future releases, including break intervals and available days.
</Note>
