Skip to content

Create a leave type

This endpoint creates a leave type and can enable it in one or more locations at the same time. The request requires the leave-types:write scope. The acting user is either the API key owner or the user identified by the X-On-Behalf-Of header. The server waits for the leave type to be created and returns it with 201, or returns 202 Accepted with an operation to poll.

What the endpoint does

POST /v2/leave-types creates a new leave type. The name and color fields are required. isActive defaults to true. If you include locationIds, the endpoint also enables a leave policy in each of those locations using the settings in initialPolicy. The policy records are created in the background after the leave type itself, so they do not appear in the response. To confirm them, read GET /v2/locations/{id}/leave-policies. To change them, use PUT or PATCH /v2/locations/{id}/leave-policies/{leaveTypeId}.

Authorization and headers

Send the API key as Authorization: Bearer vt_live_<secret>. The key must carry the leave-types:write scope. Two optional headers change how the request behaves. Idempotency-Key is a 1–255 character printable ASCII string that lets you repeat a write without creating a duplicate. Each key is kept for 24 hours per API key. If you resend the identical request with the same key inside that window, the server returns the original response and adds the Idempotent-Replayed header. If the key is paired with a different request, the server answers 422 IDEMPOTENCY_KEY_REUSED. If the first request is still running, a retry answers 409 IDEMPOTENCY_REQUEST_IN_PROGRESS. A key that fails the format rules answers 400 INVALID_IDEMPOTENCY_KEY. X-On-Behalf-Of carries the ID of the user the write is performed for. Using it needs the users:act-on-behalf scope, and the key owner has to manage the target user; if either condition is unmet, the call returns 403 ON_BEHALF_OF_NOT_ALLOWED. GET requests ignore this header.

Request body fields

The body is application/json. name is required and must be 1 to 32 characters after trimming leading and trailing spaces. color is required and must match ^#[A-Fa-f0-9]{6}$. isActive is optional and defaults to true. calendarStatus is optional and accepts "Busy" or "Free" to control how leaves of this type appear on connected Outlook or Google calendars. awayStatus is optional and controls whether users on this leave type get a Slack away status; awayStatusIcon and awayStatusMessage are optional strings that may be empty. locationIds is an optional array of location IDs; it defaults to an empty array, which enables the leave type nowhere. initialPolicy is an optional object whose fields all have defaults. Unknown fields fail validation.

initialPolicy defaults and fields

Every initialPolicy field is optional and has a default. quota defaults to 0 and is measured in quotaUnit; the maximum is 365 days or 2920 hours. quotaUnit defaults to "days" and accepts "days" or "hours". maxRollover defaults to 0 and is capped at 365 days or 2920 hours. hasUnlimitedDays defaults to false. shortestLeaveInterval defaults to "FULL-DAY" and accepts "FULL-DAY", "HALF-DAY", "ONE-HOUR", "HALF-HOUR" or "FIFTEEN-MINUTES". hideLeaveType defaults to false. isApprovalRequired defaults to true. isReasonRequired, allowLeaveInPast and negativeBalanceAllowed each default to false. Because the defaults are real policy values, review them before you send locationIds.

Responses: 201 vs 202

A 201 response returns the created leave type in a data object with id, name, isActive, color, position and calendarStatus. position is read-only and reflects the display order set in the dashboard. A 202 response returns an operation object with id, status and url. Poll the operation URL until status is SUCCEEDED or FAILED. The Location header carries the same URL as operation.url. 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. A result that arrives later still changes the status to SUCCEEDED or FAILED.

Error codes to handle

Validation and body errors return 400 VALIDATION_ERROR with details.fields, or 400 INVALID_REQUEST_BODY. Authorization problems return 401 UNAUTHORIZED, 403 INSUFFICIENT_SCOPE, 403 ON_BEHALF_OF_NOT_ALLOWED or 403 FORBIDDEN. A name already in use returns 409 DUPLICATE_NAME. A plan limit returns 422 PLAN_LIMIT_REACHED. Idempotency-specific codes are 422 IDEMPOTENCY_KEY_REUSED, 409 IDEMPOTENCY_REQUEST_IN_PROGRESS and 400 INVALID_IDEMPOTENCY_KEY. Rate limiting returns 429 RATE_LIMITED; retry after a short wait and reuse the same Idempotency-Key for writes. A 500 INTERNAL_ERROR means retry later and, if it persists, contact support with the requestId.

Decision checklist before you send the request

  1. Confirm the key has leave-types:write and, if you are acting for another user, users:act-on-behalf. 2. Decide whether the leave type should be enabled anywhere yet. If not, omit locationIds or send an empty array. 3. If you send locationIds, review every initialPolicy field because the defaults are real policy values. 4. Choose a unique name; a duplicate returns 409 DUPLICATE_NAME. 5. If you need safe retries, generate an Idempotency-Key and reuse it only for the identical request. 6. After a 201, read GET /v2/locations/{id}/leave-policies to confirm the background policies. 7. After a 202, poll operation.url until SUCCEEDED or FAILED.

Worked example: enable a 20-day vacation policy in two locations

The supplied 'withPolicy' example creates a leave type named Vacation with color #1E90FF and calendarStatus "Busy". It sends two location IDs and an initialPolicy with quota 20, quotaUnit "days", maxRollover 5, shortestLeaveInterval "HALF-DAY" and isApprovalRequired true. Because the policies are created in the background, the 201 response contains only the leave type record; confirm the two location policies with GET /v2/locations/{id}/leave-policies afterwards. The simpler 'leaveTypeOnly' example creates Parental leave with color #8A2BE2 and no locations, so it is enabled nowhere until you add policies separately.

Frequently asked questions

What scope does POST /v2/leave-types require?

The key must carry leave-types:write. If you use X-On-Behalf-Of, the key also needs users:act-on-behalf and the key owner must manage the target user.

Does creating a leave type with locationIds also create leave policies?

Yes. A leave policy is enabled in every location listed in locationIds, using the settings in initialPolicy. The policies are created in the background after the leave type, so they are not in the response. Read GET /v2/locations/{id}/leave-policies to confirm them and use PUT or PATCH /v2/locations/{id}/leave-policies/{leaveTypeId} to change them.

What happens if I omit initialPolicy?

Every initialPolicy field has a default, so omitting it still produces a policy with those defaults: a quota of 0 days, full-day leaves and approval required. Review the defaults before you send locationIds.

Why did I get 409 DUPLICATE_NAME?

Another leave type already uses the name you sent. Choose a different name and retry. If you are retrying a write, reuse the same Idempotency-Key only for the identical request.

What should I do with a 202 response?

Poll operation.url until status is SUCCEEDED or FAILED. If status is UNKNOWN, 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 the status.

How do I retry safely?

Attach an Idempotency-Key made of 1 to 255 printable ASCII characters. Each API key keeps its idempotency keys for 24 hours. Inside that window, resending the identical request with the same key returns the stored original response and adds the Idempotent-Replayed header. Pairing the key with a different request yields 422 IDEMPOTENCY_KEY_REUSED; a retry sent while the first request is still running yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; a key that breaks the format rules yields 400 INVALID_IDEMPOTENCY_KEY.

curl -X POST "$API_BASE_URL/v2/leave-types" \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Parental leave",
    "color": "#8A2BE2"
  }'
{
  "data": {
    "id": "leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615",
    "name": "Vacation",
    "isActive": true,
    "color": "#1E90FF",
    "position": 0,
    "calendarStatus": "Busy"
  }
}
{
  "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": "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"
  }
}

Idempotency-Key

FieldTypeRequiredDescriptionConstraints
Idempotency-KeystringNooptional 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

FieldTypeRequiredDescriptionConstraints
X-On-Behalf-OfstringNoID 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

FieldTypeRequiredDescriptionConstraints
bodyobjectYes
body.namestringYesleave type name, 1 to 32 characters after trimming leading and trailing spaces1 <= length <= 32
body.colorstringYesleave type color in #RRGGBB format^#[A-Fa-f0-9]{6}$
body.isActivebooleanNowhether the leave type is activetrue
body.calendarStatusstringNohow leaves of this type appear on connected calendars (Outlook, Google)"Busy" | "Free"
body.awayStatusbooleanNowhether users on leave of this type get an away status in Slack
body.awayStatusIconstringNothe Slack status emoji; may be empty
body.awayStatusMessagestringNothe Slack status text; may be empty
body.locationIdsarray<string>NoIDs of the locations to enable this leave type in, with the settings from initialPolicy. The policies are created in the background after the leave type.[]
body.locationIds[]string
body.initialPolicyobjectNothe leave policy used for each location in locationIds . Every field is optional and has a default.
body.initialPolicy.quotanumberNothe yearly quota, in quotaUnit; at most 365 days or 2920 hours0
0 <= value
body.initialPolicy.quotaUnitstringNothe unit of quota and maxRollover"days"
"days" | "hours"
body.initialPolicy.maxRollovernumberNothe maximum unused quota that rolls over into the next leave year, in quotaUnit; at most 365 days or 2920 hours0
0 <= value
body.initialPolicy.hasUnlimitedDaysbooleanNowhether the leave type grants unlimited leavefalse
body.initialPolicy.shortestLeaveIntervalstringNo"FULL-DAY"
"FULL-DAY" | "HALF-DAY" | "ONE-HOUR" | "HALF-HOUR" | "FIFTEEN-MINUTES"
body.initialPolicy.hideLeaveTypebooleanNowhether the leave type is hidden from users when they request leavefalse
body.initialPolicy.isApprovalRequiredbooleanNowhether leaves of this type need approvaltrue
body.initialPolicy.isReasonRequiredbooleanNowhether a reason is requiredfalse
body.initialPolicy.allowLeaveInPastbooleanNowhether users can request leave for past datesfalse
body.initialPolicy.negativeBalanceAllowedbooleanNowhether a user's balance can go negativefalse

response

FieldTypeRequiredDescriptionConstraints
responseobjectReturned 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.operationobjectYes
response.operation.idstringYes
response.operation.statusstringYesoperation 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.urlstringYes

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