Rota Planning API · Contract v1 · Zero PII

API Reference

Stateless HTTPS JSON service at https://api.optonomicon.com. Plan compliant multi-option rotas, check legal cover for a shift in milliseconds, and replan around absences — without ever transmitting names or personal data.

1. Base URL, authentication & headers

All endpoints are served over HTTPS at https://api.optonomicon.com. Every endpoint except /v1/health and /v1/ready requires a Bearer token.

Header / PropertyRequirementBehaviour
Authorization Required (except probes) Bearer <api_key>. Keys are isolated per tenant; one key cannot read or cancel another tenant's jobs.
Content-Type On POST application/json (UTF-8, max 2 MB).
X-Request-Id Optional Up to 64 chars matching [A-Za-z0-9._-]. Echoed back on the response (generated automatically if omitted).
Response headers Always set Cache-Control: no-store, X-Content-Type-Options: nosniff, X-Request-Id, plus Retry-After on HTTP 429.
Zero-PII by schema: Unknown JSON properties (such as name or email) are rejected with 400 unknown_property. Jobs are held only in memory and purged automatically 1 hour after completion. See Privacy & Security.

2. Quickstart

Planning a period is asynchronous: POST /v1/rota/jobs validates the request and returns 202 Accepted with a jobId, then you poll GET /v1/rota/jobs/{id} until status is done.

1. Submit a planning jobbash / curl
curl -sS -X POST https://api.optonomicon.com/v1/rota/jobs \
  -H "Authorization: Bearer $OPTONOMICON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contract": 1,
    "start": "2026-12-07",
    "days": 7,
    "shifts": [
      {"id": "early", "start": "07:00", "end": "15:00", "role": "rn"},
      {"id": "night", "start": "22:00", "end": "07:30", "role": "rn"}
    ],
    "staff": [
      {"id": "emp-1", "roles": ["rn"], "contractHoursPerWeek": 36},
      {"id": "emp-2", "roles": ["rn"], "contractHoursPerWeek": 36, "unavailable": ["2026-12-10"]},
      {"id": "emp-3", "roles": ["rn"], "contractHoursPerWeek": 36, "requests": [{"date": "2026-12-13", "kind": "off"}]}
    ],
    "cover": [
      {"date": "2026-12-07", "shift": "early", "required": 1},
      {"date": "2026-12-07", "shift": "night", "required": 1}
    ],
    "rules": {"minRestHours": 11, "maxConsecutiveDays": 5, "maxConsecutiveNights": 3},
    "solve": {"timeLimitSeconds": 8}
  }'
2. Poll until done (typically every 500–1000 ms)bash / curl
curl -sS https://api.optonomicon.com/v1/rota/jobs/"$JOB_ID" \
  -H "Authorization: Bearer $OPTONOMICON_API_KEY"

3. Endpoints

MethodPathAuthSuccessPurpose
GET /v1/health None 200 Liveness probe: {"status":"ok","contract":1}.
GET /v1/ready None 200 Readiness & live capacity: uptimeSeconds, activeJobs, capacity.
POST /v1/rota/jobs Bearer 202 Submit a planning period. Returns job status envelope with jobId.
GET /v1/rota/jobs/{id} Bearer 200 Poll status (queued, running, done, cancelled, failed) and read result when done.
DELETE /v1/rota/jobs/{id} Bearer 200 Cooperatively cancel a queued or running job (works for plans and replans).
POST /v1/rota/swaps Bearer 200 Synchronous legal cover check for one shift in a live rota (typically 10–45 ms).
POST /v1/rota/replans Bearer 202 Async minimal-disruption replan around one or more absences. Poll/cancel via /v1/rota/jobs/{id}.

4. Request schema (POST /v1/rota/jobs)

One person works at most one shift per calendar date. A shift belongs to the calendar date it starts on, so an overnight shift starting on Monday evening belongs to Monday. All IDs (shifts[].id, staff[].id, role) must match [A-Za-z0-9][A-Za-z0-9_.:-]{0,63}.

Top-level fields

FieldTypeRequiredDescription
contractintegerYesMust be 1.
startYYYY-MM-DDYesFirst date of the planning period.
daysintegerYesLength of period in days (1–56; need not be whole weeks).
shiftsShift[]Yes1 to 40 shift definitions.
staffStaff[]Yes1 to 150 staff (or your key's maxStaff cap).
coverCover[]YesRequired headcount per (date, shift), counting already-assigned fixed shifts.
rulesRulesNoWorking-time rules. Omit a field or set 0 to switch it off.
solveSolveNotimeLimitSeconds (1–120, default 20 for plans, 10 for replans) and seed (default 1).

shifts[]

FieldTypeRequiredDescription
idstringYesUnique shift identifier (cannot collide with a staff ID).
startHH:MMYes24-hour local start time (00:00–23:59).
endHH:MMYes24-hour local end time. If end ≤ start, the shift ends the next calendar day.
paidMinutesintegerNoMinutes counted toward hours rules & fairness (defaults to shift duration; useful for unpaid breaks).
rolestringNoRequired role ID. Omit if any staff member may work this shift.

Night shift definition: for maxConsecutiveNights, a shift counts as a night shift when at least 3 hours (180 minutes) of it fall between 23:00 and 06:00.

staff[]

FieldTypeRequiredDescription
idstringYesOpaque unique staff identifier (e.g. emp-14).
rolesstring[]NoRole IDs this person holds.
contractHoursPerWeeknumberNoContracted weekly hours (0–168). When supplied for everyone, fairness balances proportional contractShare rather than raw hours.
maxHoursPerWeeknumberNoPersonal ceiling on average weekly hours (0–168). Overrides rules.maxAverageHoursPerWeek when lower.
unavailableYYYY-MM-DD[]NoDates within the period this person cannot work (e.g. approved leave).
fixed{date, shift}[]NoShifts already held inside the period. Kept intact on /jobs; treated as the editable live rota on /swaps and /replans.
history{date, shift}[]NoShifts worked up to 14 days before start so rest, consecutive-day, night-run and rolling 7-day rules hold across day 1.
requestsRequest[]NoSoft preferences: {date, kind, shift?, weight?} where kind is off, work, shift (requires shift), or avoid (requires shift). Optional weight 0.1–100 (default 1).

cover[] & rules

Object / FieldType / RangeDescription
cover[].date / shift / requireddate, id, 0..maxStaffTotal headcount needed for that shift on that date (including anyone already in staff[].fixed).
rules.minRestHoursnumber (0–24)Minimum uninterrupted rest between the end of one shift and the start of the next.
rules.maxConsecutiveDaysinteger (0–days)Maximum working days in a row without a day off.
rules.maxAverageHoursPerWeeknumber (0–168)Period average weekly paid hours ceiling across the planning horizon.
rules.maxHoursInSevenDaysnumber (0–168)Hard rolling 7-day paid hours ceiling (applies to every sliding 7-day window).
rules.maxConsecutiveNightsinteger (0–days)Maximum consecutive night shifts (≥3 h in 23:00–06:00).

5. Planning response (GET /v1/rota/jobs/{id})

While queued or running, the endpoint returns status: "queued" or "running" with elapsedMillis. Once status is "done", result has outcome: "solved" (with up to four distinct rule-verified options: cover, requests, fairness, balanced; duplicates are merged into also) or outcome: "infeasible" with an actionable explanation.

Solved job response (200 OK)application/json
{
  "jobId": "job-9f41b2c0",
  "status": "done",
  "elapsedMillis": 5420,
  "timeLimitSeconds": 8,
  "result": {
    "outcome": "solved",
    "options": [{
      "id": "cover",
      "also": ["requests"],
      "metrics": {
        "coverRequired": 178, "coverFilled": 178,
        "requestsTotal": 10, "requestsMet": 10,
        "hoursMin": 41.5, "hoursMax": 73.5, "hoursSpread": 9.12,
        "contractShareMin": 0.79, "contractShareMax": 0.98, "contractShareSpread": 0.05
      },
      "assignments": [
        {"staff": "emp-1", "date": "2026-12-07", "shift": "early"}
      ],
      "unfilled": [],
      "unmetRequests": [],
      "hours": [
        {"staff": "emp-1", "hours": 64.0, "contractShare": 0.89}
      ]
    }],
    "warnings": [],
    "engine": {
      "solveMillis": 5420,
      "timeLimitSeconds": 8,
      "terminated": "CONVERGED"
    }
  }
}
  • assignments contains newly assigned shifts only (shifts already passed in staff[].fixed are kept and omitted from assignments).
  • engine.terminated is one of CONVERGED, COMPLETED, DEADLINE_EXCEEDED, CANCELLED, or NOT_SEARCHED.
  • On outcome: "infeasible", explanation.kind is either KEPT_SHIFTS_BREAK_RULES (listing keptShifts: [{staff, date, shift, breaks}]) or a diagnosed rule conflict (rules, text, findings).

6. Live cover checks (POST /v1/rota/swaps)

Send the current rota in staff[].fixed and add a swap: {"staff": "...", "date": "YYYY-MM-DD"} block. The endpoint answers synchronously (200 OK, typically 10–45 ms), ranking every other staff member by whether they can legally take or swap that shift — valid stand-ins with the day off first, then valid exchanges, lightest load first, and exact broken rules for everyone who cannot.

Response from POST /v1/rota/swaps (200 OK)application/json
{
  "staff": "emp-13",
  "date": "2026-12-10",
  "shift": "ca-early",
  "candidates": [
    {
      "staff": "emp-15", "kind": "take", "valid": true,
      "breaks": [], "hours": 56.0, "contractShare": 0.75, "againstRequest": false
    },
    {
      "staff": "emp-23", "kind": "swap", "shift": "ca-late", "valid": true,
      "breaks": [], "hours": 52.0, "contractShare": 0.87, "againstRequest": false
    },
    {
      "staff": "emp-2", "kind": "take", "valid": false,
      "breaks": [{"staff": "emp-2", "rule": "role"}],
      "hours": 72.0, "contractShare": 1.0, "againstRequest": false
    }
  ],
  "warnings": []
}

7. Sick-call replans (POST /v1/rota/replans)

Send the live rota in staff[].fixed and add a replan block describing who is away. Nothing before from changes (defaults to the earliest absence date), and other people's shifts may move only within windowDays (0–14, default 2) around the absence.

Additional request blockapplication/json
"replan": {
  "absent": [
    {"staff": "emp-13", "dates": ["2026-12-14", "2026-12-15"]}
  ],
  "from": "2026-12-14",
  "windowDays": 2
}
Replan option excerpt (via GET /jobs/{id})application/json
{
  "id": "cover",
  "also": [],
  "metrics": {
    "coverRequired": 178, "coverFilled": 178,
    "released": 2, "changes": 3, "staffChanged": 3
  },
  "changes": [
    {"staff": "emp-13", "date": "2026-12-14",
     "from": "ca-late", "to": null, "away": true},
    {"staff": "emp-23", "date": "2026-12-14",
     "from": null, "to": "ca-late", "away": false}
  ]
}

Returns up to three options merged when identical: cover (most shifts filled, fewest changes), standins (only people with the day off step in), and open (shifts left open, nobody else moved). If the rota in use already breaks a rule, returns outcome: "infeasible" with explanation.kind: "ROTA_IN_USE_BREAKS_RULES" naming the conflicting shifts.

8. Canonical rule names

Every rule violation returned in breaks, keptShifts, or explanation.rules uses one of these eight names:

Rule nameMeaning
minRestHoursMinimum rest hours between consecutive shifts.
maxConsecutiveDaysMaximum working days in a row.
maxAverageHoursPerWeekGeneral average weekly paid-hours cap.
maxHoursPerWeekEmployee's personal weekly paid-hours cap (staff[].maxHoursPerWeek).
maxHoursInSevenDaysRolling 7-day paid-hours ceiling.
maxConsecutiveNightsMaximum consecutive night shifts (≥3 h in 23:00–06:00).
roleEmployee does not hold the shift's required role.
unavailableDate is listed in staff[].unavailable.

9. Limits & error codes

Default server ceilings (plan-specific keys may specify custom maxStaff, rate, or concurrency caps):

  • Problem size: up to 150 staff, 56 days, 40 shift types, 14 carry-in history days, 120 s max solve limit, 2 MB max request body.
  • Job retention: finished jobs remain readable for 1 hour in memory.

All errors use a consistent envelope: {"error": {"code": "...", "message": "...", "path": "$.optional.path"}}.

HTTPCode(s)Meaning
400 invalid_json, unsupported_contract, unknown_property, missing, invalid_type, invalid_value, out_of_range, duplicate_id, duplicate_cover, unknown_shift, unknown_staff, nothing_to_plan, nothing_to_cover, unsupported Request validation failed. error.path pinpoints the exact JSON location (e.g. $.staff[0].name).
401 unauthorized, key_expired Missing/invalid Bearer token, or key passed its UTC expiry date.
404 unknown_job, not_found Job ID does not exist, expired after 1 hour, or belongs to a different tenant key.
405 method_not_allowed Unsupported HTTP verb for that route.
413 too_large Request payload exceeds the 2 MB ceiling.
429 rate_limited, too_many_jobs Tenant POST/min rate limit or concurrent-job ceiling reached. Honour the Retry-After response header.
500 internal_error Unexpected server failure. Quote X-Request-Id if reporting.

Ready to test against api.optonomicon.com?

Run a live solve in the browser playground right now, or email us for a 14-day pilot API key matched to your team size.