Acting on behalf of users with API v2
Use the X-On-Behalf-Of header to run a v2 request as a different workspace user, such as creating a leave request for an employee from an HR tool. The change is applied as that user, under the same rules that would apply if they acted themselves.
Send the request as another user
Unless you direct otherwise, a keyed call is executed in the name of whoever owns that key. When you need to act for someone else — for instance, filing a leave entry for a worker through an HR system — place that person's user ID in the X-On-Behalf-Of header. The protected example module code0001 shows a POST to create a leave, with the Authorization, X-On-Behalf-Of, and Content-Type headers and a JSON body containing leaveTypeId, startDate, and endDate. Leaving the header out, or supplying the owner's own ID, keeps the action with the owner. A header sent with no value triggers a VALIDATION_ERROR rejection.
Requirements and reach
The key needs the users:act-on-behalf scope. Because this is a sensitive action, it is never enabled by default. The target user must also be someone the key owner manages. Use this reach check before calling the API:
- Administrator: anyone in the workspace
- Location admin: users in the locations they manage
- Approver: users in the departments they approve
- User: nobody except themselves
The intersection rule
A request on behalf of a user is allowed only if both sides may do it. The key, and therefore its owner, must have the scopes the request needs. The target user's own role must allow the same scopes. Consider an admin key carrying leaves:approve alongside users:act-on-behalf, used to sign off a worker's leave: it is refused, since that worker's role carries no approval rights. Delegation does not enlarge the worker's permissions, nor does it transfer the admin's permissions to them.
Errors
Check the error code before retrying, because each code points to a different fix:
- INSUFFICIENT_SCOPE, 403: the key lacks users:act-on-behalf or a scope the request needs.
- ON_BEHALF_OF_NOT_ALLOWED, 403: the target is outside the key owner's reach, with details.reason TARGET_OUTSIDE_REACH, or the target's role does not allow the request, with details.reason TARGET_NOT_PERMITTED and details.missingScopes.
- RESOURCE_NOT_FOUND, 404: no user with this ID exists in the workspace.
- VALIDATION_ERROR, 400: X-On-Behalf-Of is present but empty.
What the audit trail shows
Records credit the delegated user as the actor, appending the integration name where one is configured — e.g. "Marcus Rodriguez (through HR_BOT)". That attribution surfaces across the leave timeline, notifications, and company logs. In addition, company logs retain the key owner, giving admins a path from any entry back to the originating key and the individual accountable for it. The key's activity in the dashboard lists each write request with the user it acted as.
| Key owner | Can act on behalf of |
|---|---|
| Administrator | Anyone in the workspace |
| Location admin | Users in the locations they manage |
| Approver | Users in the departments they approve |
| User | Nobody (only themselves) |
Reach depends on the key owner's role; the target must be within the managed scope.
| Code | Status | When |
|---|---|---|
| INSUFFICIENT_SCOPE | 403 | The key does not have users:act-on-behalf, or a scope the request needs. |
| ON_BEHALF_OF_NOT_ALLOWED | 403 | Target outside reach (TARGET_OUTSIDE_REACH) or target role does not allow the request (TARGET_NOT_PERMITTED, with details.missingScopes). |
| RESOURCE_NOT_FOUND | 404 | No user with this ID exists in the workspace. |
| VALIDATION_ERROR | 400 | X-On-Behalf-Of is present but empty. |
Use details.reason and details.missingScopes where present to distinguish reach from permission failures.
Frequently asked questions
What happens if I omit the header or send my own ID?
Without the header, a request runs as the key owner. Sending the owner's own ID has the same effect. An empty header value is rejected.
Why can an administrator key fail to approve leave for an employee?
Both sides must allow the action. The key owner needs the required scopes, and the target user's role must also allow those scopes. Neither side can lend the other extra power.
How is an on-behalf-of change recorded?
The target user is shown as the actor, with the integration name added when present. Company logs also record the key owner, and dashboard activity lists each write with the user it acted as.
curl -X POST $API_BASE_URL/v2/leaves \
-H "Authorization: Bearer vt_live_..." \
-H "X-On-Behalf-Of: <userId>" \
-H "Content-Type: application/json" \
-d '{ "leaveTypeId": "...", "startDate": "2026-10-05", "endDate": "2026-10-09" }'