The moveUserDepartment operation reassigns a user to a different department within the REST API v2. This page documents the exact request shape, permission rules, response codes, and error recovery so you can integrate the call confidently.
Endpoint and method
Send a PUT request to the path shown below. The path parameter id identifies the user to move. The request body must be JSON containing a departmentId string — the ID of the destination department. The operation is defined in the contract schema module schema0004.
Authorization and scopes
The API key must be sent as a Bearer token in the Authorization header and must carry the users:write scope. The key owner — or the user identified by the optional X-On-Behalf-Of header — must be an admin, or a location admin who manages the target user. If the acting user lacks that authority, the request fails with 403 FORBIDDEN or 403 ON_BEHALF_OF_NOT_ALLOWED. See the authentication and scopes documentation for key creation and role limits.
Headers
Two optional headers affect the call. Idempotency-Key (1–255 printable ASCII characters) lets you retry the write without duplicating it. Each API key keeps its keys for 24 hours; if you resend the same request with the same key inside that window, the API returns the original response and adds the Idempotent-Replayed header. Sending a different request under an existing key yields 422 IDEMPOTENCY_KEY_REUSED, a retry that arrives while the first request is still running yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and a malformed key yields 400 INVALID_IDEMPOTENCY_KEY. X-On-Behalf-Of names the user the write is performed for; it needs the users:act-on-behalf scope, and the key owner must manage that user, or the call fails with 403 ON_BEHALF_OF_NOT_ALLOWED. The header is ignored on GET requests.
Request body
The body must be application/json and contain a single required field: departmentId (string), the ID of the department to move the user to. Omitting it produces 400 VALIDATION_ERROR. The TypeScript definition is available in the request body section of the reference.
Responses
A successful synchronous move returns 200 with the updated user object, including the new departmentId. If the move is still running, or if it succeeded but the user cannot be read back because the move took them outside the key's data reach, the API returns 202 Accepted with an operation object containing id, status, and url. Poll the operation URL until status is SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check. A later result still changes status to SUCCEEDED or FAILED.
Error codes
The endpoint can return: 400 VALIDATION_ERROR (departmentId missing); 401 UNAUTHORIZED (missing or malformed key); 403 FORBIDDEN (acting user lacks permission); 403 ON_BEHALF_OF_NOT_ALLOWED (on-behalf-of user not permitted); 404 RESOURCE_NOT_FOUND (user does not exist, is outside the key's data reach, or department does not exist); 409 CONFLICT (request conflicts with current state); 422 IDEMPOTENCY_KEY_REUSED or other unprocessable entity; 429 RATE_LIMITED; and 500 INTERNAL_ERROR. Each error envelope includes a code, name, description, resolution, and requestId for support.
Decision checklist: 200 vs 202 vs 404
Use this checklist to interpret the outcome. (1) If you receive 200, the move completed and the user object reflects the new departmentId — no further action. (2) If you receive 202, the move was accepted but the result is not yet readable; poll the operation URL. Do not assume success until status is SUCCEEDED. (3) If you receive 404, either the user or the department does not exist, or the user is outside the key's data reach. Check both IDs and the key's scope before retrying. (4) If you receive 403, verify the acting user's role and, when using X-On-Behalf-Of, that the key owner manages the target user.
Worked example
A request to move user user-cfe5d39b-f1f0-45aa-85cd-ce93e637a262 to department team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6 sends PUT /v2/users/user-cfe5d39b-f1f0-45aa-85cd-ce93e637a262/department with body {"departmentId":"team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6"}. A 200 response returns the user object with departmentId set to team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6. A 202 response returns an operation object such as {"operation":{"id":"pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93","status":"PENDING","url":"/v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93"}}; poll that URL until status changes.
Frequently asked questions
What happens if the move takes the user outside the key's data reach?
The move is accepted and the response is 202 Accepted with an operation to poll. The user cannot be read back with that key, so you must rely on the operation status to confirm the outcome.
Can a location admin move a user to another department?
Yes, provided the location admin manages the target user. Otherwise the request fails with 403 FORBIDDEN.
What does the Idempotency-Key header do for this endpoint?
It lets you resend the write without risking a duplicate. Each API key keeps its idempotency keys for 24 hours. If you repeat the identical request with the same key inside that window, you get the original response back, marked with the Idempotent-Replayed header. Pairing the key with a different request produces 422 IDEMPOTENCY_KEY_REUSED; sending a retry while the first attempt is still in flight produces 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; a key that fails the 1–255 printable ASCII rule produces 400 INVALID_IDEMPOTENCY_KEY.
What should I do if I receive a 404 RESOURCE_NOT_FOUND?
Check that both the user ID and the departmentId exist and that the user is within the key's data reach. If the user is outside the key's reach, the move may still have been accepted with a 202 — verify via the operation URL.
{
"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
Yes
body.departmentId
string
Yes
the ID of the department to move the user to
response
Field
Type
Required
Description
Constraints
response
object
response.data
object
No
response.data.id
string
Yes
user ID
response.data.name
string
Yes
user name
response.data.email
string
Yes
user email
response.data.isAdmin
boolean
Yes
a boolean that tells you if the selected user is an admin
response.data.locationId
string | null
Yes
the ID of the user's location, null when the user has none yet
response.data.locationId[variant1]
string
the ID of the user's location, null when the user has none yet
response.data.locationId[variant2]
null
the ID of the user's location, null when the user has none yet
response.data.departmentId
string | null
Yes
the ID of the user's department, null when the user has none yet
response.data.departmentId[variant1]
string
the ID of the user's department, null when the user has none yet
response.data.departmentId[variant2]
null
the ID of the user's department, null when the user has none yet
response.data.status
string
Yes
user status
"ACTIVE" | "INACTIVE" | "DELETED"
response.data.employeeId
string | null
Yes
the employee ID set on the user profile page, null when it is not set
response.data.employeeId[variant1]
string
the employee ID set on the user profile page, null when it is not set
response.data.employeeId[variant2]
null
the employee ID set on the user profile page, null when it is not set
response.data.startDate
string | null
Yes
employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.startDate[variant1]
string
employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.startDate[variant2]
null
employment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.endDate
string | null
Yes
employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.endDate[variant1]
string
employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.endDate[variant2]
null
employment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.labels
array<object>
Yes
labels assigned to the user
response.data.labels[]
object
response.data.labels[].id
string
Yes
response.data.labels[].name
string
Yes
response.data.labels[].color
string
Yes
response.data.location
object
No
the user's location (only when expand includes location)
response.data.location.id
string
Yes
location ID
response.data.location.name
string
Yes
location name
response.data.location.timezone
string
No
the location's IANA time zone, left out when none is stored
response.data.location.isDefault
boolean
Yes
whether this is the company's default location
response.data.location.createdAt
string
Yes
a timestamp in the ISO 8601 format
date-time
response.data.department
object
No
the user's department (only when expand includes department)
response.data.department.id
string
Yes
department ID
response.data.department.name
string
Yes
department name
response.data.department.isDefault
boolean
Yes
whether this is the company's default department
response.data.department.createdAt
string
Yes
a timestamp in the ISO 8601 format
date-time
response.data.holidays
array<HolidayYear>
No
public holidays for the user's location, grouped by year (only when expand includes holidays)
response.data.holidays[]
object
response.data.holidays[].year
integer
No
the year for the holidays
response.data.holidays[].holidays
array<object>
No
response.data.holidays[].holidays[]
object
response.data.holidays[].holidays[].id
string
No
holiday ID
response.data.holidays[].holidays[].name
string
No
holiday name
response.data.holidays[].holidays[].date
string
No
date in YYYY-MM-DD format
date
response.data.holidays[].holidays[].isHalfDay
boolean
No
whether it is a half-day holiday
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.