Skip to content

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 knowSendAnswer type
The balance on a specific daydate in YYYY-MM-DDBALANCE with days and hours
The earliest stretch of time off of a given sizeamount together with unitWINDOW with start date, end date and working days
Whether any window inside the horizon fitsamount together with unitNOT_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

AreaField or controlWhat it does
PathidRequired user resource ID
QueryleaveTypeIdRequired leave type to project
QuerydateOptional YYYY-MM-DD date question
QueryamountOptional size, greater than 0 and at most 1000
QueryunitRequired with amount; working, calendar or weeks
Responsequestion.typeDATE or the amount question type
Responseanswer.typeBALANCE, WINDOW or NOT_ANSWERABLE
ResponseseriesAccrual points in ascending date order
ResponsehorizonEndEnd of the next leave year
Errorerror.codeStable machine-readable code
Errorerror.requestIdInclude when contacting support
Question choice table
What you need to knowSendAnswer type
The balance on a specific daydate in YYYY-MM-DDBALANCE with days and hours
The earliest stretch of time off of a given sizeamount together with unitWINDOW with start date, end date and working days
Whether any window inside the horizon fitsamount together with unitNOT_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.

Field and control map
AreaField or controlWhat it does
PathidRequired user resource ID
QueryleaveTypeIdRequired leave type to project
QuerydateOptional YYYY-MM-DD date question
QueryamountOptional size, greater than 0 and at most 1000
QueryunitRequired with amount; working, calendar or weeks
Responsequestion.typeDATE or the amount question type
Responseanswer.typeBALANCE, WINDOW or NOT_ANSWERABLE
ResponseseriesAccrual points in ascending date order
ResponsehorizonEndEnd of the next leave year
Errorerror.codeStable machine-readable code
Errorerror.requestIdInclude 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

FieldTypeRequiredDescriptionConstraints
idstringYesresource ID.

leaveTypeId

FieldTypeRequiredDescriptionConstraints
leaveTypeIdstringYesthe ID of the leave type to project.

date

FieldTypeRequiredDescriptionConstraints
datestringNothe date to read the projected balance on, in YYYY-MM-DD format. Send it instead of amount and unit .Format: date

amount

FieldTypeRequiredDescriptionConstraints
amountnumberNothe 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

FieldTypeRequiredDescriptionConstraints
unitstringNothe 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

FieldTypeRequiredDescriptionConstraints
responseobject
response.dataobjectYes
response.data.userIdstringYesthe ID of the user the projection is for
response.data.leaveTypeIdstringYesthe ID of the projected leave type
response.data.questionLeaveProjectionDateQuestion | LeaveProjectionAmountQuestionYesthe question the answer belongs to, as it was understood from the query parameters
response.data.question[variant1]objectthe question asked with the date query parameter
response.data.question[variant1].typestringYes
response.data.question[variant1].datestringYesthe date the balance was asked for, in YYYY-MM-DD formatFormat: date
response.data.question[variant2]objectthe question asked with the amount and unit query parameters
response.data.question[variant2].typestringYes
response.data.question[variant2].amountnumberYesthe size of the time off that was asked about, in unit
response.data.question[variant2].unitstringYesthe 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.answerLeaveProjectionBalanceAnswer | LeaveProjectionWindowAnswer | LeaveProjectionNotAnswerableAnswerYesthe answer to the question. Read type first; NOT_ANSWERABLE carries the horizon instead of a result.
response.data.answer[variant1]objectthe answer to a date question
response.data.answer[variant1].typestringYes
response.data.answer[variant1].datestringYesthe date the balance is projected for, in YYYY-MM-DD formatdate
response.data.answer[variant1].daysnumberYesthe projected balance in days
response.data.answer[variant1].hoursnumberYesthe projected balance in hours, converted with the user's working hours
response.data.answer[variant2]objectthe answer to an amount question
response.data.answer[variant2].typestringYes
response.data.answer[variant2].startDatestringYesthe 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].endDatestringYesthe 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].workingDaysnumberYesthe working days the window costs
response.data.answer[variant3]objectreturned 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].typestringYes
response.data.answer[variant3].horizonEndstringYesthe last date the projection reaches, in YYYY-MM-DD formatdate
response.data.seriesarray<LeaveProjectionPoint>Yesthe 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[].datestringYesthe accrual date, in YYYY-MM-DD formatdate
response.data.series[].daysnumberYesthe projected balance on that date in days
response.data.series[].hoursnumberYesthe projected balance on that date in hours
response.data.horizonEndstringYesthe last date the projection reaches, the end of the next leave year, in YYYY-MM-DD formatdate

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo