Skip to content

v2 API authentication and API keys

Every request to the v2 REST API is authenticated with an API key sent as a bearer token in the Authorization header. Keys are created in the dashboard, scoped to specific capabilities, capped by the creator's role, and can be expired, rotated or revoked. This guide walks through each of those controls in the order you'll meet them while building an integration.

Sending the key

A v2 key is presented as a bearer token. The key itself begins with the prefix vt_live_. A request without a key, or with a key the API does not recognise, returns 401 UNAUTHORIZED. A key that exists but is no longer usable returns 403 KEY_REVOKED or 403 KEY_EXPIRED depending on why it stopped. v1 keys sent in x-api-key are not accepted by v2; you need a v2 key.

Creating a key

Key creation happens in the dashboard, under Add-ons → Open API. Only administrators can create keys today. The create form collects the following inputs, each with its own constraints and visibility rules.

Create-key form map

Use this map to plan what each field affects before you submit the form.

Scopes

Each capability has a read and a write scope. Write implies read. The capability table below shows which scopes exist and what each capability covers. A request that needs a scope the key does not hold returns 403 INSUFFICIENT_SCOPE, and the missing scopes are listed in details.requiredScopes.

Special scopes for sensitive actions and reasons

Four scopes sit outside the read/write pattern. They gate approving and denying, acting as another user, reading the reason fields on requests, and seeing hidden leave-type names. None of them is implied by any :write scope.

Expanding related resources

Expanding a related resource is a convenience, not a permission bypass: the key must already hold the read scope for whatever it embeds, in addition to the endpoint's own scope. Think of it as a second request folded into the first — it can only surface data a direct read would already allow. When the scope is missing, the call fails and details.expand lists the values responsible. You can resolve it either by adding the listed scopes to the key in the dashboard or by removing those values from expand. Related IDs are unaffected by this rule: userId and approverId are always returned, so a key holding only leaves:read can still join leaves to people by ID.

The one case that does not fail

There is a single exception to the fail-on-missing-scope rule. When you expand user or approver, the embedded user object also carries location and department — objects you never named in expand. If the key lacks locations:read or departments:read, the request still succeeds, but those nested objects are silently dropped. The ID fields (locationId, departmentId) remain. The example below shows a key that holds departments:read but not locations:read: department is embedded and location is absent.

Webhooks and scopes

A webhook inherits the scope profile of the key that created it, and its payload carries the same reason and statusReason fields. If that key lacks leaves:read-reason, leave.* and toil.* events arrive with both fields as null. The scope snapshot is refreshed whenever a key edits the webhook, so the key that last touched the destination is the one whose scopes apply. Rotating a key or changing its scopes does not automatically update an existing webhook: send any PATCH /v2/webhooks/{id} with that key to refresh the snapshot. Webhooks created in the dashboard are different — they have no key behind them, so no scope snapshot applies and reasons are always included. Which events reach a dashboard webhook is still governed by its owner's role and data reach, so it never delivers a request the owner could not open in the app.

Role ceiling and data reach

Every key is subject to two separate limits. The first is the role ceiling: a key can only be granted scopes that its creator's role already holds, so the available permission set is capped at the owner's level. The second is data reach: even when a scope is present, the key only returns records its owner is entitled to see. The role table below sets out the highest scopes and the data reach associated with each owner role. An owner is always inside their own data reach, including where the department or location they belong to is not one they approve or manage. Being named as a substitute approver does not widen a key's reach. Anything outside the data reach is treated as nonexistent and answers with 404 RESOURCE_NOT_FOUND. Because data reach follows the role alone, a key can expose less than its owner can open in the app: a user's key returns only that user's leaves, while the same person can browse colleagues' approved leaves on the calendar. The Visibility add-on does not change data reach, since reach is already confined to what the add-on permits.

Expiration

Each key is issued with an expiration setting. After the chosen period elapses, requests made with that key answer with KEY_EXPIRED, and the practical remedy is to issue a replacement key. The Never setting removes the automatic cutoff, which means the key remains usable until someone revokes it; treat that option as suitable only where the integration is actively monitored and a revocation process exists.

Rotation

Rotation produces a new secret for the same key, shown a single time, while the key identity, name and permissions are carried over unchanged. The rotation step also asks how long the outgoing secret should remain valid. Only one previous secret can be honored at a time, so rotating again ends any overlap still in progress. A key that has already been revoked cannot be rotated.

Revocation

Revocation is designed to take effect quickly, with the documented expectation that a revoked key stops working within a minute. There are two routes. An administrator can revoke a key by hand in the dashboard and may attach a note. Alternatively, revocation can follow automatically when the owner loses a privilege the key depends on: the owner is no longer an administrator, now manages fewer locations or approves fewer departments, or has been deactivated or deleted. Webhooks belonging to that owner are revoked in the same way. A request made with a revoked key answers KEY_REVOKED, where details.revocationCode identifies the cause and details.revocationReason explains it in words. The same reason is shown on the key in the dashboard, and revoked keys remain in the key list so administrators can review what happened. Two related codes cover the automatic cases: KEY_OWNER_INACTIVE applies when the owner was deactivated or deleted, and KEY_SCOPES_EXCEED_ROLE applies when the owner's role no longer permits the scopes the key carries.

Failure distinction checklist

Before you debug a failing request, check which of these matches the response. Each one points to a different fix.

Worked example: a leave-listing integration

Suppose you want to list October 2026 leave requests with each request's user embedded. The endpoint GET /v2/leaves requires leaves:read. Adding expand=user requires users:read as well. If the key has only leaves:read, the request fails with 403 INSUFFICIENT_SCOPE and details.expand names user. Add users:read to the key, or drop expand=user and match on userId instead. If you keep expand=user and the key also lacks locations:read, the request succeeds but the nested location object is missing from each embedded user; locationId is still present. If you also need the reason each person wrote, add leaves:read-reason; without it reason and statusReason come back as null and every other field is unchanged.

Capability scopes
CapabilityScopesCovers
leavesleaves:read, leaves:writeLeave requests
toiltoil:read, toil:writeTime off in lieu requests
balancesbalances:readLeave balances (read only)
usersusers:read, users:writeUsers and their settings
locationslocations:read, locations:writeLocations and work weeks
departmentsdepartments:read, departments:writeDepartments
leave-typesleave-types:read, leave-types:writeLeave types
leave-policiesleave-policies:read, leave-policies:writeLeave policies per location
holidaysholidays:read, holidays:writePublic holidays per location
labelslabels:read, labels:writeLabels
automationsautomations:read, automations:writeAutomations
notificationsnotifications:read, notifications:writeNotifications and scheduled reports
webhookswebhooks:read, webhooks:writeWebhooks

Write implies read. Read & write includes read and also allows deleting.

Special scopes
ScopeGrantsAlso implies
leaves:approveApprove and deny leave and TOIL requests.leaves:read, toil:read
users:act-on-behalfSend requests as another user with X-On-Behalf-Of.users:read
leaves:read-reasonRead reason and statusReason on leave and TOIL requests. Without it both come back as null and every other field is unchanged. Seeing a TOIL request at all still needs toil:read.leaves:read
leave-types:read-hiddenSee the names of hidden leave types. Without it, a hidden leave type shows as "Hidden Leave Type" in the embedded leaveType.name of leaves (with expand=leaveType) and in the leaveTypeName of balances and quotas. leaveTypeId and every amount are kept.leave-types:read

No :write scope implies any of these four.

Scopes required by expand values
EndpointexpandAlso requires
GET /v2/leaves, GET /v2/leaves/{id}userusers:read
—approverusers:read
—leaveTypeleave-types:read
GET /v2/users, GET /v2/users/{id}locationlocations:read
—departmentdepartments:read
—holidaysholidays:read

The endpoint's own scope is required in addition to the expand scope.

Role ceiling and data reach
Owner roleHighest scopesData reach
AdministratorEvery scopeThe whole workspace
Location adminApprover scopes, plus users:write, locations:read/write, departments:read/write, leave-policies:read/write, holidays:write, notifications:read/writeUsers in the locations they manage
ApproverUser scopes, plus leaves:approve, users:act-on-behalf, leave-types:read-hiddenUsers in the departments they approve
Userleaves:read/write, leaves:read-reason, toil:read/write, balances:read, users:read, holidays:read, leave-types:readOnly themselves

The key owner is always in their own data reach. Resources outside the data reach return 404 RESOURCE_NOT_FOUND.

Expiration options
OptionKey stops working
30 days30 days after creation
90 days90 days after creation
1 year (default)1 year after creation
NeverOnly when revoked

An expired key returns KEY_EXPIRED.

Rotation overlap options
OptionPrevious secret
24 hours (recommended)Keeps working for 24 hours, so you can deploy the new secret without downtime
7 daysKeeps working for 7 days
Stop nowStops working immediately. Use this when a secret has leaked

Only one previous secret works at a time; rotating again ends any overlap still running.

Failure distinction checklist
ResponseMeaningFix
401 UNAUTHORIZEDMissing or unknown keyCheck the Authorization header and that the key is a v2 key
403 KEY_EXPIREDKey passed its expirationCreate a new key
403 KEY_REVOKEDKey was revoked manually or automaticallyRead details.revocationReason, then ask an admin to create a new key
403 INSUFFICIENT_SCOPEKey lacks a required scopeAdd the scopes in details.requiredScopes, or drop the expand values in details.expand
404 RESOURCE_NOT_FOUNDResource is outside the key's data reachConfirm the owner's role and data reach

Related revocation codes: KEY_OWNER_INACTIVE and KEY_SCOPES_EXCEED_ROLE.

Frequently asked questions

Why do I get 401 UNAUTHORIZED instead of 403 KEY_EXPIRED?

401 UNAUTHORIZED means the key is missing or unknown to the API. 403 KEY_EXPIRED means the key is recognised but has passed its expiration. 403 KEY_REVOKED means the key was revoked. Each points to a different fix: check the header for 401, create a new key for KEY_EXPIRED, and read details.revocationReason for KEY_REVOKED.

Can I use my existing v1 key with v2?

No. v1 keys sent in x-api-key do not work on v2. Create a v2 key in the dashboard instead.

Why is location missing from an embedded user when I expand user?

expand=user embeds a user that carries location and department even though you did not ask for them by name. If the key lacks locations:read, the request still succeeds but the nested location object is dropped; locationId remains. The same applies to departments:read and the department object. Add the missing scope if you need the nested object.

Should I rotate or revoke a key?

Rotate when you want a new secret while keeping the same key, name and permissions. Choose the overlap option that fits your deployment: 24 hours, 7 days, or stop now if the secret has leaked. Revoke when the key should stop working entirely. Revoked keys cannot be rotated.

Why are reason and statusReason null?

The key lacks leaves:read-reason. Without that scope both fields come back as null and every other field is unchanged. Seeing a TOIL request at all still needs toil:read. Webhooks created by a key without leaves:read-reason also deliver reason and statusReason as null.

curl "$API_BASE_URL/v2/leaves?startDate=2026-10-01&endDate=2026-10-31" \
  -H "Authorization: Bearer vt_live_..."
{
  "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": "...",
    "details": {
      "requiredScopes": ["users:read", "leave-types:read"],
      "expand": ["user", "leaveType"]
    }
  }
}
{
  "id": "LR4",
  "userId": "u1",
  "user": {
    "id": "u1",
    "name": "Ada Lovelace",
    "locationId": "loc-1",
    "departmentId": "team-1",
    "department": { "id": "team-1", "name": "Engineering", "isDefault": true }
  }
}
{
  "error": {
    "code": "KEY_REVOKED",
    "name": "KeyRevoked",
    "description": "Example post details.",
    "resolution": "See details.revocationReason for why it was revoked, then ask a OnlyLeave admin to create a new key.",
    "requestId": "...",
    "details": { "revocationCode": "...", "revocationReason": "..." }
  }
}