Skip to content

Move a user to another location via the API

Use this endpoint when an employee's workplace changes and their future leave calculations must follow the destination's rules. The call updates the user's location, then recalculates upcoming leave using the new location's work week, public holidays and leave policies. Because the recalculation can take time, the endpoint sometimes completes synchronously and sometimes hands back an operation to poll.

Before you call: admin check and inputs

Before sending the request, confirm three things: the acting user is an admin, the key carries the users:write scope, and you have the correct user ID and destination location ID. The request is a PUT to the user location route, with the user ID in the path and the destination supplied in a JSON body. The protected contract modules schema0001, schema0004 and schema0008 define the exact path parameter, operation and body shape; refer to those modules rather than retyping field definitions.

Checklist:

  • Confirm the acting user (key owner, or the X-On-Behalf-Of user when that header is used) is an admin. Location admins and approvers are rejected with 403 FORBIDDEN.
  • Confirm the key has the users:write scope and is sent as a Bearer token in the Authorization header.
  • Confirm the destination locationId is present; omitting it returns 400 VALIDATION_ERROR.
  • Confirm both the user and the destination location exist and are within the key's data reach; otherwise the response is 404 RESOURCE_NOT_FOUND.
  • Decide whether to send an Idempotency-Key so a retry after a network failure is safe.

200 versus 202: which outcome to handle

Two success outcomes are possible, and they mean different things for your code.

A 200 response means the move finished before the response was sent. The returned user object carries the new locationId, so you can update your local record immediately. The protected module code0002 shows the shape of that response.

A 202 response means the move is still running, or it finished but the result cannot be read back through this key. That second case happens when the move takes the user outside the key's data reach. In either case the response contains an operation with an ID, a status and a URL to poll, as shown in protected module code0003. Poll that URL until the status is SUCCEEDED or FAILED. If the status becomes UNKNOWN, no result arrived within the stated window and the change may or may not have been applied, so read the user resource to verify before retrying.

Practical distinction: treat 200 as 'done, use the returned user' and 202 as 'not done yet, poll the operation'. Do not treat 202 as a failure, and do not assume the user's location has changed until polling reports SUCCEEDED.

Safe retries and acting on behalf of a user

Adding an Idempotency-Key is optional, yet it protects this write against duplicate execution. Supply the same value again with an identical payload during the retention period and the earlier reply is returned rather than applying the move a second time. Changing the payload while keeping that value is rejected with 422 IDEMPOTENCY_KEY_REUSED. A second attempt arriving before the first has finished yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, while a malformed value yields 400 INVALID_IDEMPOTENCY_KEY. Protected modules schema0002 and schema0006 specify the precise constraints for this header.

Use X-On-Behalf-Of to indicate whose behalf the write is being carried out for. That usage depends on holding the users:act-on-behalf scope, and the key owner also needs authority over the named target; lacking either condition produces 403 ON_BEHALF_OF_NOT_ALLOWED. Protected modules schema0003 and schema0007 give the exact header contract. Remember how this interacts with the admin rule: when this header is present, the named user becomes the acting user for the admin check, so naming a location admin there still results in 403 FORBIDDEN.

Troubleshooting by status code

Work through failures in this order, because each points to a different fix:

  • 400 VALIDATION_ERROR: the locationId is missing or invalid. Fix the body fields listed in the error details and resend. Protected module code0004 shows the error envelope.
  • 401 UNAUTHORIZED: the key is missing, malformed or unrecognized. Send a valid key as a Bearer token. See protected module code0005.
  • 403 FORBIDDEN: the acting user is not an admin. Switch to an admin acting user; adding scopes alone will not fix this.
  • 403 ON_BEHALF_OF_NOT_ALLOWED: the X-On-Behalf-Of usage is not permitted for this key owner and target user. Check the users:act-on-behalf scope and whether the key owner manages the target.
  • 404 RESOURCE_NOT_FOUND: the user does not exist or is outside the key's data reach, or the destination location does not exist. Check each ID separately, since one code covers all of them. See protected module code0007.
  • 409, 422, 429 and 500: these cover conflicts with current state, idempotency reuse, rate limiting and internal errors. For rate limiting, wait and retry using the same Idempotency-Key for writes, as shown in protected module code0010. For internal errors, retry later and quote the requestId if the problem persists, as shown in protected module code0011.

Every error uses the same envelope with a stable code, a human-readable name, a description, a resolution hint and a requestId, defined in protected modules schema0011 through schema0018. Log the requestId with every failure so support can trace the request.

Worked example: relocating an employee

A typical relocation flow looks like this: an admin key sends the PUT with the user ID in the path and the destination locationId in the body, plus an Idempotency-Key. If the recalculation of future leave finishes quickly, the response is 200 and the returned user shows the new locationId; update your records from that response. If the recalculation is still running, the response is 202 with an operation URL; poll it until SUCCEEDED, then read the user to confirm the new location before notifying downstream systems. If the destination is outside the key's data reach, expect 202 even after the move completes, and verify through a key that can read the user.

Interpreting the response
OutcomeMeaningYour next step
200Move completed synchronouslyUse the returned user with the new locationId
202Move still running, or result not readable by this keyPoll the operation URL until SUCCEEDED or FAILED
202 with UNKNOWN statusNo result arrived in time; change may or may not be appliedRead the user resource to verify before retrying

200 returns the updated user; 202 returns an operation to poll, including when the moved user is outside the key's data reach.

Frequently asked questions

Can a location admin move a user to another location?

A location admin or approver acting through the key owner or the X-On-Behalf-Of user is not sufficient for this endpoint; that combination returns 403 FORBIDDEN. Use an admin acting user.

Why did the move return 404 RESOURCE_NOT_FOUND?

Check whether the user ID exists and is within the key's data reach, and whether the destination location exists. The same 404 code covers all three cases, so verify each identifier separately.

What should I do after a 202 response?

Poll the operation URL returned in the 202 response until its status becomes SUCCEEDED or FAILED. If it becomes UNKNOWN, read the user resource to check whether the change was applied.

curl -X PUT "$API_BASE_URL/v2/users/string/location" \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1"
  }'
{
  "data": {
    "id": "user-cfe5d39b-f1f0-45aa-85cd-ce93e637a262",
    "name": "John Chao",
    "email": "[email protected]",
    "isAdmin": false,
    "locationId": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
    "departmentId": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
    "status": "ACTIVE",
    "employeeId": "E-1024",
    "startDate": "2022-11-08",
    "endDate": null,
    "labels": [
      {
        "id": "969f8429-7dc3-48a1-96b1-6049a99dda06",
        "name": "contractor",
        "color": "#FF0000"
      }
    ]
  }
}
{
  "operation": {
    "id": "pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93",
    "status": "PENDING",
    "url": "/v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93"
  }
}
{
  "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

FieldTypeRequiredDescriptionConstraints
idstringYesresource ID.

Idempotency-Key

FieldTypeRequiredDescriptionConstraints
Idempotency-KeystringNooptional 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

FieldTypeRequiredDescriptionConstraints
X-On-Behalf-OfstringNoID 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

FieldTypeRequiredDescriptionConstraints
bodyobjectYes
body.locationIdstringYesthe ID of the location to move the user to

response

FieldTypeRequiredDescriptionConstraints
responseobject
response.dataobjectNo
response.data.idstringYesuser ID
response.data.namestringYesuser name
response.data.emailstringYesuser email
response.data.isAdminbooleanYesa boolean that tells you if the selected user is an admin
response.data.locationIdstring | nullYesthe ID of the user's location, null when the user has none yet
response.data.locationId[variant1]stringthe ID of the user's location, null when the user has none yet
response.data.locationId[variant2]nullthe ID of the user's location, null when the user has none yet
response.data.departmentIdstring | nullYesthe ID of the user's department, null when the user has none yet
response.data.departmentId[variant1]stringthe ID of the user's department, null when the user has none yet
response.data.departmentId[variant2]nullthe ID of the user's department, null when the user has none yet
response.data.statusstringYesuser status"ACTIVE" | "INACTIVE" | "DELETED"
response.data.employeeIdstring | nullYesthe employee ID set on the user profile page, null when it is not set
response.data.employeeId[variant1]stringthe employee ID set on the user profile page, null when it is not set
response.data.employeeId[variant2]nullthe employee ID set on the user profile page, null when it is not set
response.data.startDatestring | nullYesemployment 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]stringemployment 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]nullemployment start date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.endDatestring | nullYesemployment 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]stringemployment 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]nullemployment end date as stored, an ISO 8601 date or timestamp (the same value v1 returns), null when it is not set
response.data.labelsarray<object>Yeslabels assigned to the user
response.data.labels[]object
response.data.labels[].idstringYes
response.data.labels[].namestringYes
response.data.labels[].colorstringYes
response.data.locationobjectNothe user's location (only when expand includes location)
response.data.location.idstringYeslocation ID
response.data.location.namestringYeslocation name
response.data.location.timezonestringNothe location's IANA time zone, left out when none is stored
response.data.location.isDefaultbooleanYeswhether this is the company's default location
response.data.location.createdAtstringYesa timestamp in the ISO 8601 formatdate-time
response.data.departmentobjectNothe user's department (only when expand includes department)
response.data.department.idstringYesdepartment ID
response.data.department.namestringYesdepartment name
response.data.department.isDefaultbooleanYeswhether this is the company's default department
response.data.department.createdAtstringYesa timestamp in the ISO 8601 formatdate-time
response.data.holidaysarray<HolidayYear>Nopublic holidays for the user's location, grouped by year (only when expand includes holidays)
response.data.holidays[]object
response.data.holidays[].yearintegerNothe year for the holidays
response.data.holidays[].holidaysarray<object>No
response.data.holidays[].holidays[]object
response.data.holidays[].holidays[].idstringNoholiday ID
response.data.holidays[].holidays[].namestringNoholiday name
response.data.holidays[].holidays[].datestringNodate in YYYY-MM-DD formatdate
response.data.holidays[].holidays[].isHalfDaybooleanNowhether it is a half-day holiday

response

FieldTypeRequiredDescriptionConstraints
responseobjectReturned 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.operationobjectYes
response.operation.idstringYes
response.operation.statusstringYesoperation 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.Allowed values: "PENDING" | "SUCCEEDED" | "FAILED" | "UNKNOWN"
response.operation.urlstringYes

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo