Skip to content

Cancel a TOIL request

The cancelToil operation ends a TOIL (time off in lieu) request that is still open. It needs the toil:write scope and acts either as the API key owner or as a user named in the X-On-Behalf-Of header. A reason is optional; when supplied it becomes the request's statusReason. The call either returns the updated TOIL request directly or, when the write is still processing, returns a 202 with an operation you poll until it finishes.

Endpoint and authorization

Send a POST to /v2/toil/{id}/cancel, where {id} is the TOIL request's resource ID. Authenticate with a bearer API key and make sure the key carries toil:write. The acting user — the key owner, or the user identified by X-On-Behalf-Of — may cancel their own TOIL requests or those belonging to users they manage. If you use X-On-Behalf-Of, the key also needs users:act-on-behalf and the key owner must manage the target user; otherwise the call fails with 403 ON_BEHALF_OF_NOT_ALLOWED. The header is ignored on GET requests.

Request inputs

The path parameter id is required and identifies the TOIL request. Two optional headers and one optional body field shape the call. Idempotency-Key accepts 1 to 255 printable ASCII characters and makes the write safe to retry. Each key is scoped to its API key and kept for 24 hours; within that window, resending the same request under the same key returns the stored original response and flags it with an Idempotent-Replayed header instead of running the cancellation again. Three failure modes sit around that mechanism: pointing an existing key at a different request yields 422 IDEMPOTENCY_KEY_REUSED, sending a retry before the first attempt has finished yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and a key that breaks the character or length rule yields 400 INVALID_IDEMPOTENCY_KEY. The JSON body may include reason, a string that may be empty and is stored as statusReason. On leaves, text that resembles HTML or script fails validation.

Responses: 200 versus 202

A 200 response returns the TOIL request in a data object, including its id, userId, approverId, leaveTypeId, dates, duration, locationId, departmentId, status, reason, statusReason, approvalDate and createdAt. A 202 response instead returns an operation object with id, status and url; poll that URL until the status is SUCCEEDED or FAILED. If the operation reports UNKNOWN, no result arrived within 15 minutes and the cancellation may or may not have been applied, so read the TOIL request to check. A result that arrives later still moves the operation to SUCCEEDED or FAILED. The Location header on a 202 carries the same URL as operation.url.

Field and control map

Use this map to connect what you send with what you get back. It is a reading aid, not a replacement for the endpoint contract.

Error handling and failure distinctions

The endpoint documents these specific failures: 400 VALIDATION_ERROR with details.fields, 403 ON_BEHALF_OF_NOT_ALLOWED, 403 FORBIDDEN, 404 RESOURCE_NOT_FOUND when the TOIL request does not exist or sits outside the key's data reach, 422 TOIL_REQUEST_NOT_OPEN when the request can no longer be cancelled, and the Idempotency-Key codes. The general error envelope also covers 401 UNAUTHORIZED, 409 CONFLICT, 429 RATE_LIMITED and 500 INTERNAL_ERROR. Two failures are easy to confuse: 404 means the request is missing or unreachable, while 422 TOIL_REQUEST_NOT_OPEN means it exists but is no longer open. A 403 FORBIDDEN means the acting user lacks permission; 403 ON_BEHALF_OF_NOT_ALLOWED means the on-behalf-of header itself was rejected. Every error includes a requestId to quote when contacting support.

Worked example

Suppose a user logged a TOIL request by mistake. You send a POST to /v2/toil/{id}/cancel with a JSON body of {"reason": "Logged by mistake"} and an Authorization header carrying your bearer key. If the cancellation completes immediately, the response is 200 with the TOIL request and its statusReason set to your reason. If the write is still processing, the response is 202 with an operation such as pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93 in PENDING state; you then poll /v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93 until it reports SUCCEEDED or FAILED. If you retry after a network timeout, reuse the same Idempotency-Key so the original response is replayed rather than a second cancellation attempted.

Pre-flight checklist

Before sending the call, confirm: (1) the key has toil:write; (2) if using X-On-Behalf-Of, the key also has users:act-on-behalf and the owner manages the target user; (3) the TOIL request id is correct and within the key's data reach; (4) the request is still open, since a closed request returns 422 TOIL_REQUEST_NOT_OPEN; (5) any Idempotency-Key is 1–255 printable ASCII characters and is reused only for the same request; (6) your client handles both 200 and 202, polling the operation URL on 202; (7) reason is plain text and does not resemble HTML or script.

Request and response field map
Field or controlLocationRequiredPurpose
idpathyesTOIL request resource ID
Idempotency-Keyheaderno1–255 printable ASCII characters; safe retry for 24 hours per key
X-On-Behalf-OfheadernoUser ID the write is performed for; needs users:act-on-behalf and management of the target user
reasonbody (JSON)noOptional decision reason; stored as statusReason
data.statusresponse 200—TOIL request status: OPEN, APPROVED, DENIED, CANCELLED, EXPIRED or DELETED
data.statusReasonresponse 200—Reason given at denial or cancellation; requires leaves:read-reason, otherwise null
operationresponse 202—Object with id, status and url to poll until SUCCEEDED or FAILED

Status and statusReason values are returned only when the caller has the relevant read scopes; without leaves:read-reason the reason fields are null.

Frequently asked questions

What scope does cancelToil require?

The endpoint requires toil:write. If you act on behalf of another user with X-On-Behalf-Of, the key also needs users:act-on-behalf and the key owner must manage that user.

Why did I get a 202 instead of a 200?

A 200 means the cancellation finished and the TOIL request is returned directly. A 202 means the write is still running, or succeeded but its result could not be read back yet. Poll the operation.url until the status is SUCCEEDED or FAILED. If it reports UNKNOWN, no result arrived within 15 minutes and the change may or may not have been applied; read the TOIL request to check.

What is the difference between 404 RESOURCE_NOT_FOUND and 422 TOIL_REQUEST_NOT_OPEN?

404 RESOURCE_NOT_FOUND means the TOIL request does not exist or is outside the key's data reach. 422 TOIL_REQUEST_NOT_OPEN means the request exists but can no longer be cancelled, for example because it is already approved, denied or cancelled.

Where does the reason I send end up?

The optional reason field in the JSON body is stored as the request's statusReason. It may be empty. On leaves, text that looks like HTML or script fails validation.

How should I retry a cancellation safely?

Send an Idempotency-Key header of 1 to 255 printable ASCII characters. Keys are retained for 24 hours per API key. Within that window, resending the same request under the same key replays the original response with an Idempotent-Replayed header. Pointing the key at a different request returns 422 IDEMPOTENCY_KEY_REUSED; retrying before the first attempt finishes returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; a key that breaks the character or length rule returns 400 INVALID_IDEMPOTENCY_KEY.

Why is statusReason null in the response?

The reason and statusReason fields require the leaves:read-reason scope, which covers leaves and TOIL alike. Without that scope the value is returned as null even if a reason was stored.

curl -X POST "$API_BASE_URL/v2/toil/string/cancel" \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "reason": "Logged by mistake"
  }'
{
  "data": {
    "id": "toilRequest-3b8e6c1a-2d4f-4b7a-9c5e-8f1a2b3c4d5e",
    "userId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14",
    "approverId": "user-0f3a9c1e-6c2b-4a5d-9e7f-1b2c3d4e5f60",
    "leaveTypeId": "leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615",
    "startDate": "2026-11-07",
    "endDate": "2026-11-07",
    "isFullDayLeave": true,
    "durationWorkingDays": 1,
    "locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
    "departmentId": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
    "status": "APPROVED",
    "reason": "Worked on the weekend release",
    "statusReason": null,
    "approvalDate": "2026-11-09T08:30:00.000Z",
    "createdAt": "2026-11-08T17:45:12.000Z"
  }
}
{
  "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.

body

FieldTypeRequiredDescriptionConstraints
bodyobjectNo
body.reasonstringNooptional reason for the decision, may be empty; stored as statusReason. On leaves, text that looks like HTML or script fails validation.

response

FieldTypeRequiredDescriptionConstraints
responseobject
response.dataobjectNo
response.data.idstringYesTOIL request ID
response.data.userIdstringYesan ID of the user who earned the TOIL
response.data.approverIdstring | nullYesan ID of the approver, null until the request is approved
response.data.approverId[variant1]stringan ID of the approver, null until the request is approved
response.data.approverId[variant2]nullan ID of the approver, null until the request is approved
response.data.leaveTypeIdstringYesthe ID of the leave type the TOIL is added to
response.data.startDatestringYesdate in YYYY-MM-DD formatdate
response.data.endDatestringYesdate in YYYY-MM-DD formatdate
response.data.isFullDayLeavebooleanYestrue if the TOIL covers full days, false if it covers part of a day
response.data.startHournumberNostart hour in the user's time zone (in 24h format), returned only when isFullDayLeave is false
response.data.endHournumberNoend hour in the user's time zone (in 24h format), returned only when isFullDayLeave is false
response.data.startMinutenumberNostart minutes in the user's time zone, returned only when isFullDayLeave is false
response.data.endMinutenumberNoend minutes in the user's time zone, returned only when isFullDayLeave is false
response.data.durationWorkingDaysnumberNothe duration of the TOIL in days. A full-day TOIL counts each day it covers; a part-day TOIL converts its hours using an 8-hour day, whatever the user's working hours.
response.data.locationIdstringYesthe ID of the user's location when the TOIL request was sent
response.data.departmentIdstringYesthe ID of the user's department when the TOIL request was sent
response.data.statusstringYesTOIL request status"OPEN" | "APPROVED" | "DENIED" | "CANCELLED" | "EXPIRED" | "DELETED"
response.data.reasonstring | nullYesthe reason the user gave for the TOIL. Requires the leaves:read-reason scope, which covers leaves and TOIL alike; without it the value is null .
response.data.reason[variant1]stringthe reason the user gave for the TOIL. Requires the leaves:read-reason scope, which covers leaves and TOIL alike; without it the value is null .
response.data.reason[variant2]nullthe reason the user gave for the TOIL. Requires the leaves:read-reason scope, which covers leaves and TOIL alike; without it the value is null .
response.data.statusReasonstring | nullYesthe reason given when the TOIL request was denied or cancelled, null when none was given. Requires the leaves:read-reason scope; without it the value is null .
response.data.statusReason[variant1]stringthe reason given when the TOIL request was denied or cancelled, null when none was given. Requires the leaves:read-reason scope; without it the value is null .
response.data.statusReason[variant2]nullthe reason given when the TOIL request was denied or cancelled, null when none was given. Requires the leaves:read-reason scope; without it the value is null .
response.data.approvalDatestring | nullYesa timestamp in the ISO 8601 format, null until the request is approveddate-time
response.data.approvalDate[variant1]stringa timestamp in the ISO 8601 format, null until the request is approveddate-time
response.data.approvalDate[variant2]nulla timestamp in the ISO 8601 format, null until the request is approveddate-time
response.data.createdAtstringYesa timestamp in the ISO 8601 formatdate-time

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