Approve a TOIL request with the REST API v2 endpoint
Project plan
Use this endpoint when an eligible approver needs to move an open TOIL request to APPROVED in one step. It is intended for department approvers, location admins, and admins, and it does not start a multi-step approval chain.
Endpoint and state check
Send POST to /v2/toil/{id}/approve with the TOIL request ID in the path. The operation contract is schema0004, and the required path field is schema0001. The request succeeds only while the TOIL request is OPEN; once it has been approved, denied, cancelled, expired, or deleted, approval is no longer the right action.
Who may approve
Authenticate with a bearer API key carrying the leaves:approve scope. The acting user is normally the key owner, but X-On-Behalf-Of can name the user for whom the write is performed when the users:act-on-behalf scope and management relationship allow it. In either case, that acting user must be an approver for the requester's department, a location admin, or an admin.
Optional decision reason
The JSON body is optional and contains only the optional reason field described by schema0008. Supplying a reason records it as statusReason; leaving the body out or sending an empty reason is also valid. Text that looks like HTML or script is rejected by validation on leaves. The example request is preserved as protected module code0001.
Safe retries with Idempotency-Key
Add Idempotency-Key when a client may retry after a timeout or network failure. The key must contain 1 to 255 printable ASCII characters and is retained for 24 hours per API key. Repeating the same request with the same key replays the original response with the Idempotent-Replayed header. Reusing the key for 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. These rules are defined by schema0002 and schema0006.
Reading the result: 200 versus 202
A completed approval returns 200 with the TOIL object described by schema0009 and shown in code0002. Check status for APPROVED, approverId for the approver, approvalDate for the approval timestamp, and statusReason for the decision note. If the write is still running, the endpoint returns 202 with the operation object in schema0010 and code0003; poll operation.url until the operation reaches SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes, so read the TOIL resource again before deciding whether the change was applied.
Pre-flight checklist
Before calling the endpoint, confirm four things: the TOIL ID is correct, the request is still OPEN, the acting user has approval authority for that user, and the API key has leaves:approve. During the call, reuse the same Idempotency-Key only for the identical request. After the call, treat 200 as final, poll a 202 operation to completion, and use the error code rather than the HTTP status alone when diagnosing a failure.
Errors and how to distinguish them
Validation failures return 400 VALIDATION_ERROR with details.fields identifying the fields to fix, as shown in code0004. Missing or unrecognized credentials return 401, insufficient scope returns 403 with INSUFFICIENT_SCOPE in code0006, and a revoked key is also an authentication failure. Permission failures use 403 FORBIDDEN when the acting user is not an approver, or 403 ON_BEHALF_OF_NOT_ALLOWED when acting on behalf is not allowed. A missing or unreachable TOIL request returns 404 RESOURCE_NOT_FOUND in code0007. State conflicts return 409 CONFLICT in code0008, insufficient balance returns LEAVE_NEGATIVE_BALANCE in code0009, a non-open TOIL request returns 422 TOIL_REQUEST_NOT_OPEN, rate limiting returns 429 RATE_LIMITED in code0010, and server failures return 500 INTERNAL_ERROR in code0011. All error responses use the envelope in schema0011 through schema0018, including requestId for support follow-up.
Worked example
For a worked example, approve a one-day, full-day TOIL request for 2026-11-07 by sending the reason Thanks for covering the release. A successful response identifies the requester, approver, leave type, location, and department, sets status to APPROVED, and includes approvalDate. The original reason for earning the TOIL remains separate from statusReason, which holds the approver's decision note. The captured example values are preserved in code0001 and code0002.
Frequently asked questions
Does TOIL approval require multiple levels?
No. Approval is a single decision by an eligible approver, location admin, or admin. There is no chain of subsequent approvals for TOIL.
What happens to the optional reason?
The body is optional. When a reason is supplied, it is saved as statusReason on the request; it may also be empty.
How do I know whether approval finished synchronously?
A 200 response returns the approved TOIL request directly. A 202 response returns an operation object to poll until it reaches SUCCEEDED or FAILED.
Which errors distinguish permission, visibility, and state problems?
Use 403 FORBIDDEN when the acting user is not an approver for that user, 403 ON_BEHALF_OF_NOT_ALLOWED when acting on behalf is not permitted, 404 RESOURCE_NOT_FOUND when the request is missing or outside the key's reach, and 422 TOIL_REQUEST_NOT_OPEN when it is no longer open.
curl -X POST "$API_BASE_URL/v2/toil/string/approve" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"reason": "Thanks for covering the release"
}'
{
"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.