Project a user's leave balance
The user projection endpoint returns a forward-looking view of one leave type for one user. It covers the current leave year and the next one, and it answers exactly one of two questions: what the balance will be on a given date, or when the earliest time off of a given size fits inside the balance. The response shape depends on which question you send, so the first decision is always the question type, not the output fields.
Choose the question before you build the request
The endpoint accepts two mutually exclusive question shapes. Sending neither, sending both, or sending amount without unit fails with 400 VALIDATION_ERROR. Use the table below as a decision aid.
| What you need to know | Send | Answer type |
|---|---|---|
| The balance on a specific day | date in YYYY-MM-DD | BALANCE with days and hours |
| The earliest stretch of time off of a given size | amount together with unit | WINDOW with start date, end date and working days |
| Whether any window inside the horizon fits | amount together with unit | NOT_ANSWERABLE with the horizon end date |
The date parameter is a string in YYYY-MM-DD format. The amount parameter is a number greater than 0 and at most 1000, and it requires unit. The unit value is one of working, calendar or weeks. Whichever unit you pick, the cost is always counted in working days. The difference is what the unit measures: working sizes the window by its working-day cost, while calendar and weeks size it by a fixed span and then charge only the working days that fall inside that span. That is why a two-week window containing a public holiday or another non-working day costs fewer working days than an ordinary two weeks.
Authentication, path and query surface
The endpoint is a GET request at /v2/users/{id}/projection. The id path parameter is required and identifies the user. The leaveTypeId query parameter is also required and names the leave type to project. The key must carry the balances:read scope, sent in the Authorization header as a bearer token. The key owner's role limits which users they can ask about: themselves, anyone in the company when they are an admin, users in locations they manage as a location admin, and users in departments they approve for. Any other user fails with 403 FORBIDDEN.
How to read the three answer types
Read answer.type first. A BALANCE answer carries the date, the projected balance in days and the projected balance in hours, converted with the user's working hours. A WINDOW answer carries startDate, endDate and workingDays; the start date is always a working day, and the balance is compared on the end date because accruals continue during the time off. A NOT_ANSWERABLE answer carries horizonEnd instead of a result. It is an answer, not an error, and it never means a zero balance: it means no window inside the projection horizon covers the requested amount.
The projection reaches the end of the next leave year, and that same date is the horizonEnd in the response. The series array lists the projected balance on each accrual date in ascending order. A date between two points has the balance of the earlier point. The drop at a leave year boundary is the part of the balance that the rollover cap does not carry over.
Worked example: a date question and its series
The captured example asks for the balance on 2027-04-15. The question object records type DATE and the requested date. The answer object records type BALANCE, the same date, 6.67 days and 53.36 hours. The series shows how the balance builds: 1.67 days on 2026-11-01, 3.34 days on 2026-12-01, 5 days on 2027-01-01, then 1.67 days on 2027-02-01, 3.34 days on 2027-03-01 and 5 days on 2027-04-01. The horizonEnd is 2027-12-31.
Two details matter when you build a reader or a test. First, the answer date falls between series points, so the balance on 2027-04-15 is the balance of the earlier point, 2027-04-01. Second, the drop from 5 days on 2027-01-01 to 1.67 days on 2027-02-01 is the leave year boundary, where the rollover cap leaves part of the balance behind. The example is a reference response, not a promise about any particular user's accrual pattern.
Telling the failures apart
Several outcomes look similar but mean different things. Use this checklist before changing the request.
- 400 VALIDATION_ERROR: the question shape is wrong. Check details.fields and send exactly one of date or amount with unit.
- 401 UNAUTHORIZED: the key is missing, malformed or not recognized.
- 403 FORBIDDEN: the key owner may not see this user's projection.
- 404 RESOURCE_NOT_FOUND: the user does not exist, is outside the key's data reach, the key owner may not see the projection, or the leave type does not exist for the user. These cases share one response, so do not infer which one occurred from the status alone.
- 422 REQUEST_REJECTED: there is nothing to project. This happens when the leave type has no limit, no leave year covers today, or the user has no working hours.
- NOT_ANSWERABLE: not an error. The request was valid, but no window inside the horizon covers the amount.
The error envelope carries code, name, description, resolution and requestId, with optional details. Include the requestId when contacting support.
Field and control map
| Area | Field or control | What it does |
|---|---|---|
| Path | id | Required user resource ID |
| Query | leaveTypeId | Required leave type to project |
| Query | date | Optional YYYY-MM-DD date question |
| Query | amount | Optional size, greater than 0 and at most 1000 |
| Query | unit | Required with amount; working, calendar or weeks |
| Response | question.type | DATE or the amount question type |
| Response | answer.type | BALANCE, WINDOW or NOT_ANSWERABLE |
| Response | series | Accrual points in ascending date order |
| Response | horizonEnd | End of the next leave year |
| Error | error.code | Stable machine-readable code |
| Error | error.requestId | Include when contacting support |
| What you need to know | Send | Answer type |
|---|---|---|
| The balance on a specific day | date in YYYY-MM-DD | BALANCE with days and hours |
| The earliest stretch of time off of a given size | amount together with unit | WINDOW with start date, end date and working days |
| Whether any window inside the horizon fits | amount together with unit | NOT_ANSWERABLE with the horizon end date |
The table is a decision aid for the two question shapes; it does not add new rules beyond the endpoint description.
| Area | Field or control | What it does |
|---|---|---|
| Path | id | Required user resource ID |
| Query | leaveTypeId | Required leave type to project |
| Query | date | Optional YYYY-MM-DD date question |
| Query | amount | Optional size, greater than 0 and at most 1000 |
| Query | unit | Required with amount; working, calendar or weeks |
| Response | question.type | DATE or the amount question type |
| Response | answer.type | BALANCE, WINDOW or NOT_ANSWERABLE |
| Response | series | Accrual points in ascending date order |
| Response | horizonEnd | End of the next leave year |
| Error | error.code | Stable machine-readable code |
| Error | error.requestId | Include when contacting support |
The map reflects the documented request and response fields; it is not a schema replacement.
Frequently asked questions
Can I send both date and amount with unit in one request?
No. The endpoint answers exactly one question. Sending both, sending neither, or sending amount without unit fails with 400 VALIDATION_ERROR. Choose date when you need a balance on a specific day; choose amount with unit when you need the earliest window of that size.
Is NOT_ANSWERABLE an error?
No. It is a valid answer that means no window inside the projection horizon covers the requested amount. It carries the horizon end date instead of a window, and it never means a zero balance.
Why does a missing user and a user with nothing to project return different statuses?
A user that does not exist, is outside the key's data reach, or whose projection the key owner may not see returns 404 RESOURCE_NOT_FOUND. A user with nothing to project, such as a leave type without a limit, no leave year covering today, or no working hours, returns 422 REQUEST_REJECTED. The first is about reach and existence; the second is about the data needed for a projection.
How do I read the balance for a date that is not in the series?
Use the balance of the earlier series point. The series lists accrual dates in ascending order, and a date between two points has the balance of the earlier one.
What does the unit value change?
The cost is always counted in working days, but the unit decides how the window is sized. The working unit sizes it by working-day cost directly. The calendar and weeks units size it by a fixed span and then charge only the working days inside that span, so the same two weeks cost fewer working days when they contain a public holiday or a non-working day.
curl -X GET "$API_BASE_URL/v2/users/string/projection?leaveTypeId=leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615" \
-H "Authorization: Bearer "{
"data": {
"userId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14",
"leaveTypeId": "leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615",
"question": {
"type": "DATE",
"date": "2027-04-15"
},
"answer": {
"type": "BALANCE",
"date": "2027-04-15",
"days": 6.67,
"hours": 53.36
},
"series": [
{
"date": "2026-11-01",
"days": 1.67,
"hours": 13.36
},
{
"date": "2026-12-01",
"days": 3.34,
"hours": 26.72
},
{
"date": "2027-01-01",
"days": 5,
"hours": 40
},
{
"date": "2027-02-01",
"days": 1.67,
"hours": 13.36
},
{
"date": "2027-03-01",
"days": 3.34,
"hours": 26.72
},
{
"date": "2027-04-01",
"days": 5,
"hours": 40
}
],
"horizonEnd": "2027-12-31"
}
}{
"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": "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. |
leaveTypeId
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| leaveTypeId | string | Yes | the ID of the leave type to project. |
date
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| date | string | No | the date to read the projected balance on, in YYYY-MM-DD format. Send it instead of amount and unit . | Format: date |
amount
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| amount | number | No | the size of the time off to find the earliest date for, greater than 0 and at most 1000. Requires unit , and is sent instead of date . | 0 < value <= 1000 |
unit
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| unit | string | No | the unit of amount . Only working days count in every unit; calendar and weeks fix the span of the window instead of its cost. | Allowed values: "working" | "calendar" | "weeks" |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | |||
| response.data | object | Yes | ||
| response.data.userId | string | Yes | the ID of the user the projection is for | |
| response.data.leaveTypeId | string | Yes | the ID of the projected leave type | |
| response.data.question | LeaveProjectionDateQuestion | LeaveProjectionAmountQuestion | Yes | the question the answer belongs to, as it was understood from the query parameters | |
| response.data.question[variant1] | object | the question asked with the date query parameter | ||
| response.data.question[variant1].type | string | Yes | ||
| response.data.question[variant1].date | string | Yes | the date the balance was asked for, in YYYY-MM-DD format | Format: date |
| response.data.question[variant2] | object | the question asked with the amount and unit query parameters | ||
| response.data.question[variant2].type | string | Yes | ||
| response.data.question[variant2].amount | number | Yes | the size of the time off that was asked about, in unit | |
| response.data.question[variant2].unit | string | Yes | the unit of a requested amount. working counts working days; calendar and weeks fix the span of the window, and only the working days inside it are counted. | Allowed values: "working" | "calendar" | "weeks" |
| response.data.answer | LeaveProjectionBalanceAnswer | LeaveProjectionWindowAnswer | LeaveProjectionNotAnswerableAnswer | Yes | the answer to the question. Read type first; NOT_ANSWERABLE carries the horizon instead of a result. | |
| response.data.answer[variant1] | object | the answer to a date question | ||
| response.data.answer[variant1].type | string | Yes | ||
| response.data.answer[variant1].date | string | Yes | the date the balance is projected for, in YYYY-MM-DD format | date |
| response.data.answer[variant1].days | number | Yes | the projected balance in days | |
| response.data.answer[variant1].hours | number | Yes | the projected balance in hours, converted with the user's working hours | |
| response.data.answer[variant2] | object | the answer to an amount question | ||
| response.data.answer[variant2].type | string | Yes | ||
| response.data.answer[variant2].startDate | string | Yes | the first day of the earliest window the balance covers, in YYYY-MM-DD format. It is always a working day. | date |
| response.data.answer[variant2].endDate | string | Yes | the last day of that window, in YYYY-MM-DD format. The balance is compared on this date, because accruals continue during the time off. | date |
| response.data.answer[variant2].workingDays | number | Yes | the working days the window costs | |
| response.data.answer[variant3] | object | returned when no window within the projection horizon covers the amount. It is an answer, not an error, and never a zero balance. | ||
| response.data.answer[variant3].type | string | Yes | ||
| response.data.answer[variant3].horizonEnd | string | Yes | the last date the projection reaches, in YYYY-MM-DD format | date |
| response.data.series | array<LeaveProjectionPoint> | Yes | the projected balance on each accrual date, in ascending order. A date between two points has the balance of the earlier one. | |
| response.data.series[] | object | |||
| response.data.series[].date | string | Yes | the accrual date, in YYYY-MM-DD format | date |
| response.data.series[].days | number | Yes | the projected balance on that date in days | |
| response.data.series[].hours | number | Yes | the projected balance on that date in hours | |
| response.data.horizonEnd | string | Yes | the last date the projection reaches, the end of the next leave year, in YYYY-MM-DD format | date |
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 |