Create a holiday in a location
The REST API v2 holiday endpoint adds a holiday to a location. You can create a one-day holiday, a multi-day holiday, or a holiday that repeats every year. The endpoint requires the holidays:write scope and returns the first day of the new holiday with 201, or a 202 Accepted response containing an operation to poll.
Request shape and endpoint
Send a POST request to the location holidays route. The path parameter id identifies the location that receives the holiday. The request body is application/json and must include name and startDate. The endDate field is optional and defaults to startDate, producing a single-day holiday. When you supply endDate, it must fall in the same calendar year as startDate. The start year must be from 2020 to next year. Unknown fields fail validation, so send only the fields described in the request body contract.
Required and optional body fields
The name field is a string that cannot be blank; leading and trailing spaces are trimmed. The startDate field is a calendar date in YYYY-MM-DD format. The endDate field is also a calendar date in YYYY-MM-DD format and must share the startDate year. Three boolean fields default to false: isHalfDay marks a half-day holiday, transferIfFallsOnNonWorkingDay moves the holiday to the next working day when it lands on a non-working day, and recurring makes the holiday repeat every year. When a recurring holiday does not fall on the same calendar date each year, describe the pattern in recurringRules.
Headers: authorization, idempotency, and acting user
The Authorization header carries a Bearer token. The holidays:write scope is required. The optional Idempotency-Key header lets you retry a write without risking a duplicate. It accepts 1 to 255 printable ASCII characters and is kept for 24 hours per API key. Picture a retry after a dropped connection: resend the identical request with the identical key and you get the original response replayed, marked with the Idempotent-Replayed header, rather than a second holiday. Treat the key as a fingerprint of one exact request. Walk the retry decision in order: (1) Is the key 1 to 255 printable ASCII characters? If not, the call stops at 400 INVALID_IDEMPOTENCY_KEY. (2) Is the first attempt still running? A second send at that moment returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, so wait rather than resend. (3) Is the new payload byte-identical to the original? If it differs, the server answers 422 IDEMPOTENCY_KEY_REUSED. (4) Only when the key is valid, the first attempt has finished, and the request matches does the stored response replay with the Idempotent-Replayed header. Retention lasts 24 hours per API key, so a key older than that no longer replays. The optional X-On-Behalf-Of header names the user the write is performed for and requires the users:act-on-behalf scope; the key owner must manage the target user, otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED. This header is ignored on GET requests.
What comes back
A successful synchronous write returns 201 with the first day of the holiday. The response body includes the holiday id, the locationId, the name, the date of that day, isHalfDay, a type of custom or imported, and recurring. A multi-day holiday shares one ID across its days and includes multiDayId; a single-day holiday omits multiDayId. When the holiday was moved from a non-working day, transferredFrom carries the original date. If the write is still running, the endpoint returns 202 with an operation object containing id, status, and url. Poll that URL until the status is SUCCEEDED or FAILED. A status of UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check.
Failure distinction: validation, overlap, and invalid dates
Three error families look similar but mean different things. A 400 VALIDATION_ERROR lists the failing fields in details.fields and points to a body or header problem such as a missing name or startDate. A 409 HOLIDAY_DATES_OVERLAP means the dates collide with another holiday already assigned to the location, so the request is structurally valid but conflicts with current state. A 422 HOLIDAY_INVALID_DATES means the dates themselves are impossible: they fall in different years, the start is after the end, or the start year is outside 2020 to next year. A 404 RESOURCE_NOT_FOUND means the location does not exist or is outside the key's data reach. A 403 FORBIDDEN or 403 ON_BEHALF_OF_NOT_ALLOWED points to authorization rather than date logic.
Pre-flight checklist
Before sending the request, confirm that the key carries holidays:write, that the location id is visible to the key owner, and that startDate and endDate share a year within the allowed range. Decide whether the holiday is single-day, multi-day, or recurring. For a recurring holiday that is not on the same date every year, prepare recurringRules with exactDate and specificDaySet. If you plan to retry, generate an Idempotency-Key and reuse it only for the identical request. If you act for another user, confirm the users:act-on-behalf scope and that the key owner manages that user.
Worked example: a recurring Christmas holiday
The supplied single-day example sends name Christmas Day, startDate 2026-12-25, recurring true, and transferIfFallsOnNonWorkingDay true. Because endDate is omitted, the holiday is a single day. Because recurring is true, it repeats every year on the same calendar date. Because transferIfFallsOnNonWorkingDay is true, a year when 25 December falls on a non-working day moves the holiday to the next working day, and the response records the original date in transferredFrom. The supplied multi-day example sends name Company retreat, startDate 2026-06-18, and endDate 2026-06-19, producing a two-day holiday for that year only. The supplied weekday-rule example sends name Thanksgiving, startDate 2026-11-26, recurring true, and recurringRules with exactDate false and specificDaySet [4, 4, 11], which describes the fourth Thursday of November.
| Field | Type | Required | Default | Notes |
|---|---|---|---|---|
| name | string | yes | — | Not blank; leading and trailing spaces are trimmed; length at least 1 |
| startDate | string (date) | yes | — | First day in YYYY-MM-DD format |
| endDate | string (date) | no | startDate | Last day in YYYY-MM-DD format; must be in the same year as startDate |
| isHalfDay | boolean | no | false | Marks a half-day holiday |
| transferIfFallsOnNonWorkingDay | boolean | no | false | Moves the holiday to the next working day when it falls on a non-working day |
| recurring | boolean | no | false | Repeats every year |
| recurringRules | object | no | — | Describes how a recurring holiday repeats when it is not on the same calendar date every year |
Field names, types, requiredness, and defaults are fixed by the request body contract. The notes summarize validation behavior described in the endpoint documentation.
| Status | Code | Meaning |
|---|---|---|
| 400 | VALIDATION_ERROR | A query parameter, body field, or header failed validation; details.fields lists the failing paths |
| 400 | INVALID_REQUEST_BODY | The request body could not be parsed or accepted |
| 400 | INVALID_IDEMPOTENCY_KEY | The Idempotency-Key value is invalid |
| 403 | ON_BEHALF_OF_NOT_ALLOWED | The X-On-Behalf-Of target cannot be acted for by this key |
| 403 | FORBIDDEN | The acting user may not perform the action |
| 404 | RESOURCE_NOT_FOUND | The location does not exist or is outside the key's data reach |
| 409 | HOLIDAY_DATES_OVERLAP | The dates overlap another holiday of the location |
| 409 | IDEMPOTENCY_REQUEST_IN_PROGRESS | A retry arrived while the first request is still running |
| 422 | HOLIDAY_INVALID_DATES | Dates are in different years, the start is after the end, or the start year is outside 2020 to next year |
| 422 | IDEMPOTENCY_KEY_REUSED | The Idempotency-Key was reused with a different request |
Status codes and error codes are fixed by the endpoint contract. The meaning column paraphrases the documented resolution guidance.
Frequently asked questions
How do I create a single-day versus a multi-day holiday?
Omit endDate to create a single-day holiday; it defaults to startDate. Supply endDate to create a multi-day holiday, and make sure endDate falls in the same calendar year as startDate.
How do I create a recurring holiday that is not on the same date every year?
Set recurring to true and describe the pattern in recurringRules. The specificDaySet array uses [weekOfMonth, dayOfWeek, month], where weekOfMonth is 1 to 5, dayOfWeek is 0 (Sunday) to 6 (Saturday), and month is 1 to 12. For example, [4, 4, 11] is the fourth Thursday of November.
What is the difference between HOLIDAY_DATES_OVERLAP and HOLIDAY_INVALID_DATES?
HOLIDAY_DATES_OVERLAP (409) means the dates collide with another holiday already assigned to the location. HOLIDAY_INVALID_DATES (422) means the dates themselves are impossible: different years, start after end, or a start year outside 2020 to next year.
Can I safely retry a holiday creation request?
Yes, if you send an Idempotency-Key. It accepts 1 to 255 printable ASCII characters and is kept for 24 hours per API key. Within that window, a repeat of the same key plus the same request returns the stored original response instead of creating anything new. A key reused with a different payload answers 422 IDEMPOTENCY_KEY_REUSED, and a retry that arrives while the first attempt is still running answers 409 IDEMPOTENCY_REQUEST_IN_PROGRESS.
What should I do when the endpoint returns 202 Accepted?
The response contains an operation object with id, status, and url. Poll the operation URL until the status is SUCCEEDED or FAILED. A status of UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check.
curl -X POST "$API_BASE_URL/v2/locations/string/holidays" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"name": "Christmas Day",
"startDate": "2026-12-25",
"recurring": true,
"transferIfFallsOnNonWorkingDay": true
}'{
"data": {
"id": "holiday-4d2b7c1e-9a3f-4e5d-8c6b-1a2f3e4d5c6b",
"locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
"name": "Christmas Day",
"date": "2026-12-25",
"isHalfDay": false,
"type": "custom",
"recurring": true
}
}{
"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. |
body
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| body | object | Yes | ||
| body.name | string | Yes | holiday name, not blank; leading and trailing spaces are trimmed | 1 <= length |
| body.startDate | string | Yes | the first day, a calendar date in YYYY-MM-DD format | Format: date |
| body.endDate | string | No | the last day, a calendar date in YYYY-MM-DD format in the same year as startDate. Defaults to startDate (a single-day holiday). | Format: date |
| body.isHalfDay | boolean | No | whether it is a half-day holiday | false |
| body.transferIfFallsOnNonWorkingDay | boolean | No | whether the holiday moves to the next working day when it falls on a non-working day | false |
| body.recurring | boolean | No | whether the holiday repeats every year | false |
| body.recurringRules | object | No | how a recurring holiday repeats when it is not on the same calendar date every year | |
| body.recurringRules.exactDate | boolean | No | whether the holiday repeats on the same calendar date | |
| body.recurringRules.specificDaySet | array<integer> | No | [weekOfMonth, dayOfWeek, month] : week of the month 1 to 5, day of the week 0 (Sunday) to 6 (Saturday), month 1 to 12. [4, 4, 11] is the fourth Thursday of November. | 3 <= items <= 3 |
| body.recurringRules.specificDaySet[] | integer | |||
| body.recurringRules.specificDayDuration | integer | No | the number of days the holiday lasts from that day | 1 <= value |
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 |