# Shift Roster (VN Labour Code) API

> Generate a monthly shift roster (3 shifts 4 crews, 2×12 h…) or check yours: 12 h rest, weekly rest, 12 h/day, 40 h overtime/month, night work, holidays.

- Endpoint: `GET | POST https://apibox.io.vn/v1/vn-shift-roster`
- Category: Data & JSON
- HTML docs: https://apibox.io.vn/docs/vn-shift-roster/ (Vietnamese: https://apibox.io.vn/vi/docs/vn-shift-roster/)
- Online tool: https://apibox.io.vn/tools/vn-shift-roster/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

`action=generate` (default) builds a month (`month=YYYY-MM`, or `from`/`to`, max 31 days) for `employees` (names, or objects with `no_night`, `off` dates, `max_shifts`) or `count` people. `pattern` picks the shifts: `3x8-4crew` (3 ca 4 kíp: 8-day cycle S S C C D D O O, crews offset by 2 days), `2x12-3crew`, `2x12-4crew`, `3x8`, `2x12`, `office`, or your own `shifts` ([{ code, start, end, break_minutes }]). With `demand` (people per shift) a greedy planner fills each shift with the least-loaded eligible person, spreads nights and weekends, keeps ≥ 12 h between shifts, ≤ 6 working days in a row and the weekly normal-hours cap, and reports `unfilled` slots (`partial=true`).

`action=check` takes your `roster` ({ "Name": { "2026-12-01": "S", … } } or [{ employee, date, shift }]) and lists violations: more than 12 h of work in a day (BLLĐ Điều 107), less than 12 h of rest at a shift change (Điều 110), no 24 consecutive hours off in a 7-day block or fewer than 4 days off a month (Điều 111), overtime above 40 h/month and the yearly pace above 200 h (or `overtime_year_cap=300`), work on public holidays (overtime, from /v1/vn-holidays) and breaks to give inside shifts of 6 h or more (Điều 109). `regime=daily` uses the 8 h/day normal limit, `weekly` (default) 10 h/day and 48 h/week (`normal_week_hours`).

Results: per-employee hours, night hours (22:00–06:00), overtime, weekend and holiday shifts, and the roster grid. `format=xlsx` returns the roster sheet with a warnings sheet, `format=ics` one calendar event per shift. Up to 200 employees.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `action` | body|query | string | no | `generate` | `generate` or `check` (auto when `roster` is sent). |
| `pattern` | body|query | string | no | `3x8-4crew` | `3x8-4crew`, `2x12-3crew`, `2x12-4crew`, `3x8`, `2x12`, `office`; or `shifts`. |
| `month` | body|query | string | no | `this month` | `YYYY-MM` (or `from` + `to`, max 31 days). |
| `employees` | body | array | no |  | Names or `{ name, no_night, off: [dates], max_shifts }`; or `count`. |
| `demand` | body | object | no |  | People per shift, e.g. `{ "S": 2, "C": 2, "D": 1 }` (or one number). |
| `shifts` | body | array | no |  | Custom shifts `[{ code, start, end, break_minutes, label }]`. |
| `roster` | body | object | no |  | check: `{ "Name": { "YYYY-MM-DD": "S" } }` or `[{ employee, date, shift }]` (O = off). |
| `regime` | body|query | string | no | `weekly` | `weekly` (≤ 10 h/day, 48 h/week) or `daily` (8 h/day); also `normal_week_hours`, `overtime_year_cap`. |
| `format` | body|query | string | no | `json` | `json`, `xlsx` or `ics`. |

## Example request

```bash
curl "https://apibox.io.vn/v1/vn-shift-roster?pattern=3x8-4crew&count=8&month=2026-12" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Example response

```json
{
  "action": "generate",
  "pattern": "3x8-4crew",
  "from": "2026-12-01",
  "to": "2026-12-31",
  "shifts": [
    {
      "code": "S",
      "label": "Ca sáng",
      "start": "06:00",
      "end": "14:00",
      "hours": 8,
      "night_hours": 0,
      "break_minutes": 0
    },
    "…"
  ],
  "rules": {
    "regime": "weekly",
    "normal_day_hours": 10,
    "normal_week_hours": 48,
    "max_day_hours": 12,
    "overtime_month_cap": 40,
    "overtime_year_cap": 200,
    "min_rest_between_shifts_h": 12,
    "weekly_rest_h": 24,
    "night": "22:00–06:00"
  },
  "holidays": [],
  "method": "rotation (3 shifts 4 crews (3 ca 4 kíp): 8-day cycle S S C C D D O O, crews offset by 2 days; employee n belongs to crew n mod 4)",
  "unfilled": [],
  "partial": false,
  "ok": true,
  "violations": [],
  "summary": [
    {
      "employee": "NV1",
      "shifts": 23,
      "hours": 184,
      "night_hours": 64,
      "overtime_hours": 0,
      "holiday_hours": 0,
      "weekend_shifts": 5,
      "days_off": 8,
      "overtime_year_pace": 0,
      "year_cap": 200
    },
    "…"
  ],
  "roster": [
    {
      "employee": "NV1",
      "days": {
        "2026-12-01": "C",
        "2026-12-02": "C",
        "2026-12-03": "D",
        "2026-12-04": "D",
        "…": "…"
      }
    },
    "…"
  ],
  "notes": [
    "Shift S: give a break of at least 30 minutes inside the shift (counted as working time for continuous work ≥ 6 h; BLLĐ Điều 109, NĐ 145/2020 Điều 64).",
    "…"
  ],
  "legal": [
    "…"
  ],
  "reviewed": "2026-11-15",
  "disclaimer": "Reference only, not legal advice; check the official text."
}
```

## Use cases

- Plan a 3-shift 4-crew factory roster for next month
- Check a hospital or security roster before publishing it
- Show overtime and night hours per person for payroll
- Export staff shifts to calendars (ICS)

## FAQ

### Are 12-hour shifts legal?

A day may have at most 12 h of normal + overtime work; with a weekly regime normal hours are ≤ 10 h/day, so each 12-hour shift carries overtime and 2-shift 3-crew patterns usually exceed 40 h overtime per month.

### How long between two shifts?

At least 12 hours before moving to another shift (BLLĐ Điều 110).

### Is it an optimiser?

No: a fast greedy planner with hard limits. It reports unfilled slots instead of breaking the rules.
