Skip to content

Delete a leave type with REST API v2

Use this endpoint when a leave type should be permanently removed, not merely hidden from new requests. It is a destructive write: every OPEN and APPROVED leave using that type, dated from yesterday through five years ahead, is cancelled and the action cannot be reversed. If existing leaves must remain, deactivate the type instead.

Request essentials

Send DELETE to /v2/leave-types/{id}, placing the leave type identifier in the path. There is no request body. Authenticate with a Bearer API key carrying the leave-types:write scope. The acting user is normally the key owner, or the user named by X-On-Behalf-Of when that header is used.

Destructive effect and safer alternative

Before calling the endpoint, confirm the identifier is correct and decide whether cancellation of existing leaves is intended. Deletion affects OPEN and APPROVED leaves from yesterday through five years in the future. To preserve those leaves while preventing new requests, set isActive to false through PATCH /v2/leave-types/{id} instead.

Safe retries with Idempotency-Key

Idempotency-Key is optional but recommended for retries. It must be 1 to 255 printable ASCII characters and is retained for 24 hours per API key. Repeating the same key with the same request replays the original response, marked with the Idempotent-Replayed header. A different request under the same key returns 422 IDEMPOTENCY_KEY_REUSED; a retry while the first request is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; an invalid key returns 400 INVALID_IDEMPOTENCY_KEY.

Acting on behalf of a user

Use X-On-Behalf-Of to attribute the write to someone other than the key owner. The header carries that person's identifier, but it only works when the key also carries users:act-on-behalf and the owner is responsible for managing that person. Without both conditions, the API rejects the call with 403 ON_BEHALF_OF_NOT_ALLOWED. Read-only GET calls simply disregard this header.

Reading the result: 204 versus 202

A 204 response has an empty body and means deletion completed synchronously. A 202 response returns an operation object with an id, a status, and a url; poll that URL until the status becomes SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes, so the change may or may not have been applied and the resource should be read to verify. A later result can still move the operation to SUCCEEDED or FAILED.

Errors to handle

Expect 403 ON_BEHALF_OF_NOT_ALLOWED when acting on behalf is not permitted, 403 FORBIDDEN when the acting user may not perform the action, and 404 RESOURCE_NOT_FOUND when the leave type does not exist or was already deleted. Also handle the standard error envelope for 400, 401, 409, 422, 429, and 500 responses, including scope, conflict, rate-limit, and internal-error cases. Error bodies provide a stable code, a human-readable name, a description, a resolution, and a requestId to quote when seeking help.

Pre-flight checklist

Checklist before sending: verify the path identifier, confirm leave-types:write on the key, decide whether cancelling OPEN and APPROVED leaves is intended, add an Idempotency-Key for retry safety, add X-On-Behalf-Of only when the acting-user scope and management relationship apply, and plan to poll the operation URL when the response is 202.

Success outcomes
OutcomeMeaningNext step
204Deletion completed synchronouslyNo further action needed
202Operation still running or result not yet readablePoll operation.url until SUCCEEDED or FAILED
UNKNOWN operation statusNo result within 15 minutes; change may or may not be appliedRead the resource to verify; a later result can still update the status

204 has an empty body; 202 returns an operation to poll.

Frequently asked questions

Does deleting a leave type need a request body?

No. The endpoint accepts no payload. Supply the identifier in the path, authenticate with the required scope, and optionally add the retry and acting-user headers described below.

What is the difference between 204 and 202?

A 204 means the deletion finished with no response body. A 202 means work is still running or its result is not yet readable; poll the returned operation URL until it reports SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes, so read the resource to check whether the change was applied.

How should retries be made safe?

Use an Idempotency-Key of 1 to 255 printable ASCII characters. Repeating the same key with the same request within 24 hours replays the original response. Reusing it for a different request returns 422 IDEMPOTENCY_KEY_REUSED, retrying while the first attempt runs returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and an invalid key returns 400 INVALID_IDEMPOTENCY_KEY.

How can new requests be stopped without deleting existing leaves?

Set isActive to false with PATCH /v2/leave-types/{id}. That blocks new requests while preserving existing leaves, whereas deletion cancels every OPEN and APPROVED leave of that type from yesterday through five years in the future and cannot be undone.

curl -X DELETE "$API_BASE_URL/v2/leave-types/string" \
  -H "Authorization: Bearer "
{
  "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

FieldTypeRequiredDescriptionConstraints
idstringYesresource ID.

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.

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

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