Request and manage leave through the API

This guide is for leave workflows that need your own logic or judgment: an approval agent, an HR integration, or an app that books time off for employees. Fixed rules such as notice periods, duration limits, blackout periods and how many people can be away at once are handled by built-in automations. The REST API, MCP server and Zapier all apply the same policies, approvers and roles as the dashboard.
How a leave request moves
A leave starts as a request in OPEN status, then becomes approved or denied. It can later be edited, cancelled or deleted. Employees keep requesting leave in the dashboard, Slack or Teams. A webhook can tell your agent about each new request, and the agent can approve or deny it through the API. When the agent cannot or should not decide, it can leave the request OPEN for a person to handle.
An API key never grants more power than its owner. A user's key can manage only that user's own leave. An approver's key can also decide requests for the departments they approve, and a location admin's or administrator's key covers the locations or workspace they manage. The leave timeline shows the key's integration name next to the acting user's name, so decisions made through an integration are distinguishable.
Requesting for someone else: two different paths
There are two ways to create leave for another person, and they produce different outcomes. Use the on-behalf-of header when you want the leave to behave like an employee's own request and wait for approval. Use the userId body field when you want to add leave that is already approved, as a manager would in the dashboard. The table below shows the distinction; the exact header and field contract is in the supplied protected module.
Choose the right tool for the job
The REST API is the choice when your own rules, an AI agent or an HR tool must approve, deny or request leave. Vee lets people ask for, move or cancel their own leave in the dashboard, Slack or Teams. The MCP server lets your own AI assistant book, change or approve leave in plain language. Zapier is limited to reacting: its triggers fire when leave changes, but a Zap cannot create, modify or decide a request on its own. If a Zap needs to make a change, add a "Webhooks by Zapier" step that calls the REST API with an API key.
A quick decision checklist:
- Does the workflow need to decide a request? Use the REST API or MCP.
- Does it need to act for another employee? Use the REST API with the correct scope and role.
- Does it only need to notify or copy data elsewhere? Zapier triggers are enough.
- Is it a one-off plain-language request? MCP fits one request at a time; use the REST API for bulk or unattended work.
With the REST API
The steps below cover both sides of the workflow: requesting and changing leave from your code, and approving or denying it from an agent. The exact request and response bodies are preserved in the protected contract modules referenced alongside this page; the prose here explains what each step is for and how to sequence it.
1. Create an API key with the right scopes
Open the dashboard, choose Add-ons → Open API, and generate a key. Give Leaves the Read & write level (leaves:read, leaves:write). Then, under Sensitive actions, switch on the permissions the integration actually needs: Approve and deny requests (leaves:approve) when it decides requests or adds approved leave for other people, and Act on behalf of other users (users:act-on-behalf) when it requests leave in other people's names. A key cannot exceed its owner's role, so choose the owner with the reach the workflow needs.
2. Request leave
To find IDs, use GET /v2/leave-types and GET /v2/users. GET /v2/users/{id}/balances tells you how much the person has left before you request. When the body carries no userId, the leave belongs to whoever the key is acting as: the key owner, or the person named in X-On-Behalf-Of. A successful create answers 201 Created and returns the leave object. Its status stays OPEN while an approver has yet to act, and becomes APPROVED immediately if the leave policy requires no approval. The approverId field is populated after approval. For keys without leaves:read-reason, both reason and statusReason come back as null.
For part-day leave, send isFullDayLeave: false with startHour, startMinute, endHour and endMinute in the user's time zone. On a leave type booked in half days, the leave must last exactly half of the user's working hours that day.
When adding approved leave for someone else with userId, only overlaps, dates without working days and part-day leaves longer than a working day block it; the other policy rules are skipped. If the leave breaks an automation, you get 409 AUTOMATION_OVERRIDE_REQUIRED with details.warnings. To add it anyway, repeat the request with every listed code in overrideAutomations.
3. Edit, cancel or delete
When you edit your own leave, the full leave policy is re-checked. When you edit someone else's leave, only the overlap, working-day and part-day checks run, and automation overrides are not accepted on edits. If the leave is simply no longer needed, cancel it: the record remains in the history with status CANCELLED. Reserve delete for leave that should never have existed, such as a duplicate. The table below shows who can perform each action and which statuses it works on.
4. Approve or deny
To find requests waiting for a decision, list OPEN leaves for a date range. Then approve or deny one. Both actions need leaves:approve, work only on OPEN leave, and the acting user must be an approver (or substitute approver) of the person's department, a location admin, or an administrator. The body is optional; reason is shown to the person.
Where a department uses multi-level approval, the first decision does not close the request: it comes back still OPEN with approvedLevel: "FIRST", and a second-level approver must approve it before it is final.
5. Act for someone else
To request leave in an employee's name from an HR tool, send their user ID in X-On-Behalf-Of. The key needs users:act-on-behalf, and the key owner must manage that person. The leave is then requested as if the person did it, with every policy rule applied. When the key has an integration name, the leave timeline shows it next to the person's name, for example "Marcus Rodriguez (through HR_BOT)".
Acting for someone else requires permission on both sides: the key must carry the scope, and the person's own role must permit the action. This is why an administrator's key cannot approve leave on behalf of an employee: employees have no approval rights to delegate.
6. Make writes safe to retry
Attach an Idempotency-Key header to each write, generating a fresh random UUID for it. If that write has to be retried, reuse the original value rather than generating another. The server then recognizes the retry and will not create a duplicate leave or apply an approval twice. Each key is retained for 24 hours, scoped to the API key that sent it.
7. Handle slow writes
Every write waits for the change and returns the result: 201 for a new leave, 200 for edits, cancellations, deletions and decisions. If the change takes longer than 20 seconds, you get 202 Accepted with an operation instead. A 202 is not a failure. Poll GET /v2/operations/{id} every few seconds, backing off while it stays PENDING, until status is SUCCEEDED, FAILED or UNKNOWN, or subscribe to the operation.completed and operation.failed webhooks. Stop at UNKNOWN: no result arrived within 15 minutes, so read the leave to check whether the change was applied before you retry, with the same idempotency key. Never send the write again with a new idempotency key.
8. List leave
startDate and endDate are required, and you get every leave that overlaps the range. status is one of APPROVED (the default), OPEN, DENIED, CANCELLED, EXPIRED or DELETED, one per request. There is no filter by user, department or leave type; filter on userId, departmentId and leaveTypeId in your code. Passing expand=user,approver,leaveType returns those related objects inline; reading user and approver requires users:read, while leaveType requires leave-types:read. Results arrive in pages, so continue following nextToken until the response no longer includes one, even when a page comes back short or empty. To follow changes as they happen instead of listing, subscribe to the leave.requested, leave.added, leave.approved, leave.denied, leave.updated, leave.cancelled, leave.deleted and leave.expired webhooks.
9. Handle errors
Each error carries a stable code plus a resolution you can surface to the person or act on directly. The table below covers the errors that come up most often while managing leave, with their status and cause. The full list is in the Errors reference.
With Vee
Vee is the assistant that ships with the product. It is available to every user in the dashboard, Slack, Microsoft Teams or the mobile app, and needs no setup. Example requests include asking for two hours off on Wednesday, checking whether a week off in August clashes with anyone, moving leave to next week, or cancelling a leave request. Vee prepares the change and saves nothing until you confirm. It works on your own leave and does not approve or deny requests; approvers keep using the dashboard, Slack or Teams, or MCP and the API.
With an AI assistant (MCP)
Connect your AI client to the MCP server and ask in plain language. Examples include booking vacation from May 4 to May 8, moving a Friday off to Monday, cancelling leave next week, asking which requests are waiting and approving Ana's, or denying Mark's request for the release week and telling him to pick other dates.
The assistant uses three tools. request_leave checks a request first (mode: "preview"): working days, balance before and after, blocking errors, automation warnings, and whether approval is needed. It books it (mode: "submit") only after you confirm. update_leave edits, cancels or deletes an existing leave. decide_leave approves or denies a pending request, for approvers and above only.
The assistant can do only what your role allows in the web app. Anyone can request, change and cancel their own leave. Approvers, location admins and administrators can also book leave for the people they manage and decide their requests. Every change is made as you, never as someone else, and is recorded in the logs as done "via AI assistant (MCP)". If an automation such as a blackout period blocks a booking for someone else, the assistant shows you the warnings and overrides them only if you agree. MCP is suited to handling a single request at a time. For bulk changes, or for an integration that runs unattended, use the REST API instead.
With Zapier
Zapier triggers start a Zap when leave changes in the product. The available triggers are New Leave Request Created, New Leave Added, Leave Request Approved, Leave Request Denied, Leave Updated, Leave Cancelled and Leave Deleted. Use them to post approved leave to a team channel, add it to a shared calendar, or create a task in another tool. To request, change or approve leave from a Zap, add a "Webhooks by Zapier" step that calls the REST API with an API key.
Summary
The product remains the source of truth: the API, MCP and Zapier all enforce the same policies, automations, approvers and roles as the dashboard. No key can exceed the permissions of its owner, and sensitive actions require leaves:approve or users:act-on-behalf. X-On-Behalf-Of requests leave as the employee, pending approval; userId adds it already approved. Send an Idempotency-Key on every write, and treat 202 Accepted as "still working", not a failure. Prefer cancel over delete, and use webhooks instead of polling the leave list.
| You want to | Send |
|---|---|
| Request leave for an employee, pending approval | X-On-Behalf-Of: <their ID>, no userId |
| Add leave for an employee, already approved | userId: <their ID>, with leaves:approve |
The table summarizes the fields and their scopes.
| You want to | Use |
|---|---|
| Approve or deny leave with your own rules or an AI agent, or request leave from your own app or HR tool | REST API v2 |
| Let everyone request, move or cancel their own leave by asking, in the dashboard, Slack or Teams | Vee |
| Ask your own AI assistant to book, change or approve leave in plain language | MCP server |
| Apply your own logic in other apps when leave is requested, approved or cancelled, without coding | Zapier |
Zapier only reacts to leave events; it cannot request, change or approve leave.
| Action | Request | Who | Notes |
|---|---|---|---|
| Edit | PATCH /v2/leaves/{id} | The owner of the leave, or someone who manages them | Works on OPEN and APPROVED leave. Send only the fields you change. |
| Cancel | POST /v2/leaves/{id}/cancel | The owner of the leave, or someone who manages them | Works on OPEN and APPROVED leave. Optional reason, stored as statusReason. |
| Delete | DELETE /v2/leaves/{id} | Approvers, location admins and administrators | Removes the leave. Returns the deleted leave. |
Editing your own leave applies every policy rule again; editing someone else's applies only overlap, working day and part-day checks.
| Code | Status | Cause |
|---|---|---|
| VALIDATION_ERROR | 400 | A field is missing or invalid. details.fields lists them. |
| INSUFFICIENT_SCOPE | 403 | The key lacks a scope, for example leaves:approve when adding leave for someone else. |
| ON_BEHALF_OF_NOT_ALLOWED | 403 | The key cannot act for the user in X-On-Behalf-Of. |
| FORBIDDEN | 403 | The acting user's role does not allow the action, for example approving outside their departments. |
| RESOURCE_NOT_FOUND | 404 | The leave or user does not exist, or is outside the key's data reach. |
| AUTOMATION_OVERRIDE_REQUIRED | 409 | Adding leave for someone else breaks an automation. details.warnings lists them. |
| LEAVE_OVERLAP | 422 | The person already has leave on those dates. |
| LEAVE_NEGATIVE_BALANCE | 422 | The person does not have enough balance. |
| LEAVE_NO_WORKING_DAYS | 422 | The dates contain no working days. |
| LEAVE_START_DATE_IN_PAST | 422 | The leave type does not allow leave in the past. |
| LEAVE_REASON_REQUIRED | 422 | The leave type requires a reason. |
| LEAVE_BLACKOUT_PERIOD, LEAVE_MAXIMUM_USERS_AWAY, LEAVE_PROBATION_PERIOD, LEAVE_DURATION_LIMIT, LEAVE_NOTICE_PERIOD | 422 | The person's own request breaks an automation. Overrides do not apply to someone's own request. |
| LEAVE_REQUEST_NOT_EDITABLE | 422 | The leave can no longer be edited or cancelled. |
| LEAVE_REQUEST_NOT_OPEN | 422 | The leave was already approved, denied or cancelled. |
| IDEMPOTENCY_KEY_REUSED | 422 | The same Idempotency-Key was sent with a different request. |
The full list is in the Errors reference.
| Tool | What it does |
|---|---|
| request_leave | Checks a request first (mode: "preview"): working days, balance before and after, blocking errors, automation warnings, and whether approval is needed. Books it (mode: "submit") only after you confirm. |
| update_leave | Edits, cancels or deletes an existing leave. |
| decide_leave | Approves or denies a pending request. Approvers and above only. |
MCP fits one request at a time; use the REST API for bulk or unattended work.
| Trigger | Fires when |
|---|---|
| New Leave Request Created | Someone requests leave. |
| New Leave Added | A manager adds leave for someone (already approved). |
| Leave Request Approved | A request is approved, by an approver or automatically. |
| Leave Request Denied | A request is denied. |
| Leave Updated | A leave or request is changed. |
| Leave Cancelled | A leave or request is cancelled. |
| Leave Deleted | A leave or request is deleted. |
Zapier triggers only react to leave events; they cannot request, change or approve leave.
Frequently asked questions
Can an AI agent approve leave requests for me?
Yes. Create an API key with leaves:approve, subscribe your agent to the leave.requested webhook, and let it call POST /v2/leaves/{id}/approve or /deny. It approves as you, only for the people you can approve, and the leave timeline shows the key's integration name. For requests it cannot decide, it can leave them OPEN for you.
Can I request time off for an employee through the API?
Yes. Put the employee's ID in X-On-Behalf-Of and the leave is filed in their name and held for approval, just as if they had submitted it themselves. To record leave that is already approved, put their ID in userId instead. Either route requires the right scope on the key and the right role for whoever owns it.
What happens when the employee does not have enough balance?
You get 422 LEAVE_NEGATIVE_BALANCE back. Three ways forward: trim the dates, switch to a different leave type, or have an administrator change the quota.
How do I approve a leave request that needs two approvals?
Approve it once per level with POST /v2/leaves/{id}/approve. After the first approval the leave stays OPEN with approvedLevel: "FIRST" until a second-level approver approves it too.
Should I cancel or delete leave?
Choose cancel when the time off is simply no longer wanted, because the record remains in the history with status CANCELLED. Reserve delete for entries that should never have been there, a duplicate being the usual case.
curl -X POST $API_BASE_URL/v2/leaves \
-H "Authorization: Bearer vt_live_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 5f1c7a52-3d0e-4b8e-9d6a-2c4f0b9e1a77" \
-d '{
"leaveTypeId": "leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615",
"startDate": "2026-11-09",
"endDate": "2026-11-13",
"reason": "Family trip"
}'{
"data": {
"id": "leaveRequest-cfe5d39b-f1f0-45aa-85cd-ce93e637a262",
"userId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14",
"autoApproved": false,
"durationCalendarDays": 5,
"durationWorkingDays": 5,
"startDate": "2026-11-09",
"endDate": "2026-11-13",
"isFullDayLeave": true,
"leaveTypeId": "leaveType-fcc1e5c5-ba93-479d-bd58-8f860ba10615",
"locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
"departmentId": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
"status": "OPEN",
"reason": "Family trip",
"statusReason": null,
"approvedLevel": null,
"createdAt": "2026-10-01T09:12:40.062Z"
}
}curl -X PATCH $API_BASE_URL/v2/leaves/$LEAVE_ID \
-H "Authorization: Bearer vt_live_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{ "endDate": "2026-11-16" }'curl "$API_BASE_URL/v2/leaves?startDate=2026-01-01&endDate=2026-12-31&status=OPEN" \
-H "Authorization: Bearer vt_live_..."curl -X POST $API_BASE_URL/v2/leaves/$LEAVE_ID/approve \
-H "Authorization: Bearer vt_live_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{ "reason": "Enjoy your trip" }'{
"operation": {
"id": "pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91",
"status": "PENDING",
"url": "/v2/operations/pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91"
}
}curl "$API_BASE_URL/v2/leaves?startDate=2026-11-01&endDate=2026-11-30&expand=user,leaveType" \
-H "Authorization: Bearer vt_live_..."