Set a user's custom work week
This endpoint assigns an individual work week to a user, replacing the location-level work week for that person. It is a full replacement, not a merge: whatever custom work week the user had is overwritten by the request. The call requires the users:write scope and sends exactly one of two body shapes — a flat list of working days (optionally with hours per day), or a rotating schedule of one or more weeks.
When to use this endpoint
Use it when a single user needs a schedule that differs from their location — for example a part-time pattern, a four-day week, or a repeating rotation. If the user should simply follow the location again, use the reset endpoint (DELETE) instead. The response returns the user record, not the work week, so read the user or the location work-week endpoint if you need to confirm the applied schedule.
Request shape and field map
The request is a PUT to /v2/users/{id}/work-week with a JSON body. The path parameter id is required. Two optional headers modify the call: Idempotency-Key makes retries safe, and X-On-Behalf-Of names the user the write is performed for. The body must contain exactly one of days or schedule; workHours may accompany days, and schedule carries its own startDate and weeks.
Days or schedule: a decision checklist
Before sending, decide which body shape fits the user's pattern:
- Same days every week? Use days, with the full set of working days numbered 0 (Sunday) through 6 (Saturday). No duplicates.
- Different hours on different days? Add workHours alongside days, one entry per working day, each with day and hours.
- A pattern that repeats over more than one week? Use schedule, with startDate and a weeks array where each week lists { day, hours } per working day.
- Need to clear the custom work week entirely? Do not send an empty body; use the DELETE reset endpoint instead.
workHours requires days. Each week of schedule lists each day at most once. If the company's plan does not include custom work hours, workHours and schedule are ignored without an error and only days is applied — so a schedule-only request on such a plan would leave the user without the intended rotation.
Who can call it
The key owner, or the user named in X-On-Behalf-Of, must be an admin, or a location admin who manages the target user. Acting on behalf of another user also requires the users:act-on-behalf scope; otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED. The X-On-Behalf-Of header is ignored on GET requests.
Responses and the operation pattern
A successful call returns 200 with the user record, or 202 Accepted with an operation object to poll. The 202 path means the write is still running or its result could not be read back yet; poll operation.url until the status is SUCCEEDED or FAILED. An UNKNOWN status means no result arrived within 15 minutes, and the change may or may not have been applied — read the resource to check. The response body does not include the work week itself.
Failure distinctions
The error codes separate different causes, which helps you fix the right layer:
- 400 VALIDATION_ERROR — the body shape is wrong, for example both or neither of days and schedule. details.fields lists the offending paths.
- 403 ON_BEHALF_OF_NOT_ALLOWED — the acting user is not permitted for the target user.
- 403 FORBIDDEN — the key owner lacks the required role.
- 403 WORK_HOURS_LIMIT_REACHED — the plan's limit on custom work-hour configurations is reached.
- 404 RESOURCE_NOT_FOUND — the user does not exist or is outside the key's data reach.
- Idempotency-Key codes — 422 IDEMPOTENCY_KEY_REUSED, 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, 400 INVALID_IDEMPOTENCY_KEY.
Worked example: a two-week rotation
Suppose a user alternates between two patterns: week one works Monday and Tuesday, week two works Wednesday and Thursday, each eight hours. Send a schedule body with startDate set to the first day of the rotation and weeks as an array of two entries. The captured example uses startDate 2026-01-05 and weeks [[{day:1,hours:8},{day:2,hours:8}],[{day:3,hours:8},{day:4,hours:8}]]. Because the schedule repeats every weeks.length weeks, the rotation cycles every two weeks from that start date. If the plan does not include custom work hours, this schedule is ignored without an error — check the plan before relying on it.
| Location | Name | Required | Notes |
|---|---|---|---|
| Path | id | Yes | resource ID. |
| Header | Idempotency-Key | No | 1–255 printable ASCII characters; retained 24 hours per API key. |
| Header | X-On-Behalf-Of | No | Requires users:act-on-behalf and management of the target user. |
| Body | days | One of days/schedule | Working days 0 Sunday .. 6 Saturday, no duplicates, up to 7 items. |
| Body | workHours | No | Requires days; one entry per day, up to 7 items. |
| Body | schedule | One of days/schedule | startDate plus weeks; each week lists { day, hours } per working day. |
Field names and constraints are exact contract values; the notes summarize the supplied schema.
Frequently asked questions
How do I remove a user's custom work week?
Use the DELETE reset endpoint. It removes the custom work week so the user falls back to their location's work week. No request body is needed, and it returns 204 or 202 Accepted with an operation to poll.
Why was my schedule ignored without an error?
When the company's plan does not include custom work hours, workHours and schedule are ignored and only days is applied. Check the plan before relying on a rotating schedule or per-day hours.
Does the response include the work week?
No. A 200 returns the user record, and a 202 returns an operation to poll. To confirm the applied schedule, read the user or the location work-week endpoint.
Can I safely retry this write?
Yes, with an Idempotency-Key. A key stays valid for 24 hours per API key. If you resend the identical request with that same key inside the window, you get the original response back, flagged by the Idempotent-Replayed header, instead of a second write. Three failure modes are worth telling apart: pairing the key with a different request yields 422 IDEMPOTENCY_KEY_REUSED; sending it again while the first attempt is still running yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; and a key that is not 1–255 printable ASCII characters yields 400 INVALID_IDEMPOTENCY_KEY.
curl -X PUT "$API_BASE_URL/v2/users/string/work-week" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"days": [
1,
2,
3,
4
],
"workHours": [
{
"day": 1,
"hours": 8
},
{
"day": 2,
"hours": 8
},
{
"day": 3,
"hours": 8
},
{
"day": 4,
"hours": 6
}
]
}'{
"data": {
"id": "user-cfe5d39b-f1f0-45aa-85cd-ce93e637a262",
"name": "John Chao",
"email": "[email protected]",
"isAdmin": false,
"locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
"departmentId": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
"status": "ACTIVE",
"employeeId": "E-1024",
"startDate": "2022-11-08",
"endDate": null,
"labels": [
{
"id": "969f8429-7dc3-48a1-96b1-6049a99dda06",
"name": "contractor",
"color": "#FF0000"
}
]
}
}{
"operation": {
"id": "pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93",
"status": "PENDING",
"url": "/v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"name": "ValidationError",
"description": "Example post details.",
"resolution": "Fix the fields listed in details.fields and send the request again.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"details": {
"fields": [
{
"path": "startDate",
"message": "\"startDate\" is required"
}
]
}
}
}{
"error": {
"code": "UNAUTHORIZED",
"name": "Unauthorized",
"description": "Example post details.",
"resolution": "Send a valid API key in the Authorization header as Bearer followed by the full vt_live_ key.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "INSUFFICIENT_SCOPE",
"name": "InsufficientScope",
"description": "Example post details.",
"resolution": "Add the scopes listed in details.requiredScopes to the key in the OnlyLeave dashboard.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"details": {
"requiredScopes": [
"leaves:write"
]
}
}
}{
"error": {
"code": "RESOURCE_NOT_FOUND",
"name": "ResourceNotFound",
"description": "Example post details.",
"resolution": "Check the ID of the resource named in details.resource and that the key owner can see it.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "CONFLICT",
"name": "Conflict",
"description": "Example post details.",
"resolution": "Read the resource again and retry with up-to-date values.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "LEAVE_NEGATIVE_BALANCE",
"name": "LeaveNegativeBalance",
"description": "Example post details.",
"resolution": "Shorten the leave, use a different leave type, or ask an admin to adjust the quota.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "RATE_LIMITED",
"name": "RateLimited",
"description": "Example post details.",
"resolution": "Wait a few seconds and retry, using the same Idempotency-Key for writes.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "INTERNAL_ERROR",
"name": "InternalError",
"description": "Example post details.",
"resolution": "Retry later, and if it keeps happening, contact OnlyLeave support and quote the requestId.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}id
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| id | string | Yes | resource ID. |
Idempotency-Key
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| Idempotency-Key | string | No | optional key (1 to 255 printable ASCII characters) that makes a write request safe to retry. Keys are retained for 24 hours per API key. Retrying with the same key and the same request within those 24 hours replays the original response (with the Idempotent-Replayed header). Reusing the key with a different request returns 422 IDEMPOTENCY_KEY_REUSED ; retrying while the first request is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS ; an invalid key returns 400 INVALID_IDEMPOTENCY_KEY . | 1 <= length <= 255 |
X-On-Behalf-Of
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| X-On-Behalf-Of | string | No | ID of the user the write is performed for. Requires the users:act-on-behalf scope, and the key owner must manage the target user; otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED . Ignored on GET requests. |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | |||
| response.data | object | No | ||
| response.data.id | string | Yes | user ID | |
| response.data.name | string | Yes | user name | |
| response.data.email | string | Yes | user email | |
| response.data.isAdmin | boolean | Yes | a boolean that tells you if the selected user is an admin | |
| response.data.locationId | string | null | Yes | the ID of the user's location, null when the user has none yet | |
| response.data.locationId[variant1] | string | the ID of the user's location, null when the user has none yet | ||
| response.data.locationId[variant2] | null | the ID of the user's location, null when the user has none yet | ||
| response.data.departmentId | string | null | Yes | the ID of the user's department, null when the user has none yet | |
| response.data.departmentId[variant1] | string | the ID of the user's department, null when the user has none yet | ||
| response.data.departmentId[variant2] | null | the ID of the user's department, null when the user has none yet | ||
| response.data.status | string | Yes | user status | "ACTIVE" | "INACTIVE" | "DELETED" |
| response.data.employeeId | string | null | Yes | the employee ID set on the user profile page, null when it is not set | |
| response.data.employeeId[variant1] | string | the employee ID set on the user profile page, null when it is not set | ||
| response.data.employeeId[variant2] | null | the employee ID set on the user profile page, null when it is not set | ||
| response.data.startDate | string | null | Yes | employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | |
| response.data.startDate[variant1] | string | employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | ||
| response.data.startDate[variant2] | null | employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | ||
| response.data.endDate | string | null | Yes | employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | |
| response.data.endDate[variant1] | string | employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | ||
| response.data.endDate[variant2] | null | employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set | ||
| response.data.labels | array<object> | Yes | labels assigned to the user | |
| response.data.labels[] | object | |||
| response.data.labels[].id | string | Yes | ||
| response.data.labels[].name | string | Yes | ||
| response.data.labels[].color | string | Yes | ||
| response.data.location | object | No | the user's location (only when expand includes location) | |
| response.data.location.id | string | Yes | location ID | |
| response.data.location.name | string | Yes | location name | |
| response.data.location.timezone | string | No | the location's IANA time zone, left out when none is stored | |
| response.data.location.isDefault | boolean | Yes | whether this is the company's default location | |
| response.data.location.createdAt | string | Yes | a timestamp in the ISO 8601 format | date-time |
| response.data.department | object | No | the user's department (only when expand includes department) | |
| response.data.department.id | string | Yes | department ID | |
| response.data.department.name | string | Yes | department name | |
| response.data.department.isDefault | boolean | Yes | whether this is the company's default department | |
| response.data.department.createdAt | string | Yes | a timestamp in the ISO 8601 format | date-time |
| response.data.holidays | array<HolidayYear> | No | public holidays for the user's location, grouped by year (only when expand includes holidays) | |
| response.data.holidays[] | object | |||
| response.data.holidays[].year | integer | No | the year for the holidays | |
| response.data.holidays[].holidays | array<object> | No | ||
| response.data.holidays[].holidays[] | object | |||
| response.data.holidays[].holidays[].id | string | No | holiday ID | |
| response.data.holidays[].holidays[].name | string | No | holiday name | |
| response.data.holidays[].holidays[].date | string | No | date in YYYY-MM-DD format | date |
| response.data.holidays[].holidays[].isHalfDay | boolean | No | whether it is a half-day holiday |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Returned with HTTP 202 when a write operation is still running, or succeeded but its result could not be read back yet. The Location header carries the same URL as operation.url . Poll it until the status is SUCCEEDED or FAILED . | ||
| response.operation | object | Yes | ||
| response.operation.id | string | Yes | ||
| response.operation.status | string | Yes | operation status. UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check. A result that arrives later still changes it to SUCCEEDED or FAILED. | Allowed values: "PENDING" | "SUCCEEDED" | "FAILED" | "UNKNOWN" |
| response.operation.url | string | Yes |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |