Use this endpoint to reject a TOIL request that is still awaiting a decision. It records an optional explanation for the employee, checks that the caller is authorised to decide, and either returns the updated request or hands you an operation to poll when the write has not finished yet.
Before you call
Send a POST request to /v2/toil/{id}/deny, where id is the TOIL request identifier. Authenticate with a Bearer API key that carries the leaves:approve scope. Before calling, confirm three things: the target request is still OPEN, the acting user holds an approver, location-admin, or admin role for the requester, and you have decided what explanation — if any — the employee should see. A practical checklist is: resolve the request ID, verify its current status, confirm the caller's role and scope, choose a reason, add an Idempotency-Key if you may need to retry, then send the request and branch on the status code.
Parameters and headers
The path parameter id is required and identifies the TOIL request. Two optional headers change how the call behaves. Idempotency-Key, between 1 and 255 printable ASCII characters, makes the write safe to retry: the same key with the same request within 24 hours replays the original response, reusing it with a different request returns 422 IDEMPOTENCY_KEY_REUSED, retrying while the first attempt is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and an invalid key returns 400 INVALID_IDEMPOTENCY_KEY. X-On-Behalf-Of names the user the write is performed for; it requires the users:act-on-behalf scope and the key owner must manage that user, otherwise the call fails with 403 ON_BEHALF_OF_NOT_ALLOWED.
Optional denial reason
The JSON body is optional. Its only field is reason, an optional string that may be empty. Whatever you send is persisted as the request's statusReason and displayed to the user, so phrase it as a clear explanation rather than an internal note. Text that looks like HTML or script is rejected by validation on leave-related decisions, so send plain text. For example, an approver might explain that a release moved to a weekday, giving the employee a concrete reason for the denial.
Reading the response: 200 versus 202
The endpoint waits for the denial to complete when it can. A 200 response returns the denied TOIL request, including its status and statusReason. A 202 Accepted response means the write is still running or its result cannot yet be read back; the body contains an operation with an id, a status, and a url, and the Location header carries the same URL. Poll that URL until the operation reports SUCCEEDED or FAILED. If the status is UNKNOWN, no result arrived within 15 minutes and the change may or may not have been applied, so read the TOIL request itself before deciding whether to retry.
Telling failures apart
Distinguish failures by cause rather than treating every error the same. A 400 VALIDATION_ERROR points at specific fields listed in details.fields. A 403 FORBIDDEN means the acting user is not an approver of the requester, which is different from 403 ON_BEHALF_OF_NOT_ALLOWED, where the on-behalf arrangement itself is not permitted. A 404 RESOURCE_NOT_FOUND means the request does not exist or sits outside the key's data reach. A 422 TOIL_REQUEST_NOT_OPEN means the decision window has closed. Authentication and scope problems surface as 401 or INSUFFICIENT_SCOPE, rate limiting as 429, and unexpected server faults as 500; error bodies include a requestId to quote when seeking help.
Deny endpoint responses at a glance
Status
Meaning
What to do next
200
Denial completed; the denied TOIL request is returned
Use the returned request, including statusReason
202
Write still running or result not yet readable
Poll operation.url until SUCCEEDED or FAILED
400
Validation failed, including invalid Idempotency-Key
Fix the fields named in details.fields and resend
403
Acting user is not an approver, or on-behalf use is not allowed
Check the acting user's role and users:act-on-behalf scope
404
TOIL request missing or outside the key's data reach
Check the ID and that the key owner can see the request
422
TOIL request is not OPEN, or Idempotency-Key reused
Re-read the request; use a fresh key for a different request
Response behaviour for the deny operation; operation polling details are in the protected contract modules.
Frequently asked questions
Who is allowed to deny a TOIL request through this endpoint?
The acting user — either the API key owner or the user named in X-On-Behalf-Of — must be an approver for that person's department, a location admin, or an admin, and the key needs the leaves:approve scope.
Is a denial reason required?
No. You may omit the body entirely, or send an empty reason. When you do supply a reason, it is saved as statusReason and shown to the requesting user, so write it for that audience.
What is the difference between a 200 and a 202 response?
A 200 response returns the denied TOIL request directly. A 202 response means the write is still running; it returns an operation object with an id, status, and url that you poll until the status becomes SUCCEEDED or FAILED.
What happens if the TOIL request is no longer open?
Only a request still in OPEN status can be denied. If it has already been approved, denied, or cancelled, the call fails with 422 TOIL_REQUEST_NOT_OPEN, so read the request first and retry only if it is still open.
curl -X POST "$API_BASE_URL/v2/toil/string/deny" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"reason": "The release was moved to a weekday"
}'
{
"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
No
body.reason
string
No
optional reason for the decision, may be empty; stored as statusReason. On leaves, text that looks like HTML or script fails validation.
response
Field
Type
Required
Description
Constraints
response
object
response.data
object
No
response.data.id
string
Yes
TOIL request ID
response.data.userId
string
Yes
an ID of the user who earned the TOIL
response.data.approverId
string | null
Yes
an ID of the approver, null until the request is approved
response.data.approverId[variant1]
string
an ID of the approver, null until the request is approved
response.data.approverId[variant2]
null
an ID of the approver, null until the request is approved
response.data.leaveTypeId
string
Yes
the ID of the leave type the TOIL is added to
response.data.startDate
string
Yes
date in YYYY-MM-DD format
date
response.data.endDate
string
Yes
date in YYYY-MM-DD format
date
response.data.isFullDayLeave
boolean
Yes
true if the TOIL covers full days, false if it covers part of a day
response.data.startHour
number
No
start hour in the user's time zone (in 24h format), returned only when isFullDayLeave is false
response.data.endHour
number
No
end hour in the user's time zone (in 24h format), returned only when isFullDayLeave is false
response.data.startMinute
number
No
start minutes in the user's time zone, returned only when isFullDayLeave is false
response.data.endMinute
number
No
end minutes in the user's time zone, returned only when isFullDayLeave is false
response.data.durationWorkingDays
number
No
the 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.locationId
string
Yes
the ID of the user's location when the TOIL request was sent
response.data.departmentId
string
Yes
the ID of the user's department when the TOIL request was sent
the 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]
string
the 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]
null
the 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.statusReason
string | null
Yes
the 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]
string
the 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]
null
the 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.approvalDate
string | null
Yes
a timestamp in the ISO 8601 format, null until the request is approved
date-time
response.data.approvalDate[variant1]
string
a timestamp in the ISO 8601 format, null until the request is approved
date-time
response.data.approvalDate[variant2]
null
a timestamp in the ISO 8601 format, null until the request is approved
date-time
response.data.createdAt
string
Yes
a timestamp in the ISO 8601 format
date-time
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.