Skip to content

Remove a user's Location Admin role

This endpoint strips the Location Admin role from one user across every location they currently manage. It is a single write with no request body: you name the user in the path, authenticate with a key that carries users:write, and the service either completes the change immediately or hands back an operation to poll. The user's ordinary role survives, and so does Admin status if they hold it. Because the change narrows what the user can reach, their API keys and webhooks are revoked shortly afterward.

Endpoint at a glance

Method and path: DELETE /v2/users/{id}/location-admin. The only path parameter is id, a required string identifying the user. There is no request body. Authentication is a bearer token sent in the Authorization header, and the key must include the users:write scope. Two optional headers matter: Idempotency-Key makes the write safe to retry, and X-On-Behalf-Of lets a key act for another user when the key also holds users:act-on-behalf and its owner manages that user. The exact request and response contracts, including the cURL sample and the 202 operation payload, are delivered in the accompanying protected modules (code0001, code0002, schema0001 through schema0007).

Who is allowed to call it

Authorization is decided by the key owner's role, not just the scope on the key. The owner must be an admin, or a location admin who manages every location the target user manages. If you are acting through X-On-Behalf-Of, the same rule applies to the acting user, and the key owner must manage that user; otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED. A key missing users:write returns 403 FORBIDDEN. A user that does not exist, or sits outside the key's data reach, returns 404 RESOURCE_NOT_FOUND.

What the user keeps

Removal is scoped to the Location Admin role only. The user's regular role is untouched, and if they also hold Admin, that stays. To grant Admin instead, the documented route is PATCH /v2/users/{id} with isAdmin: true. To give Location Admin back later, use the companion endpoint that makes a user a Location Admin; note that its locationIds field is the full post-call list of managed locations, not an additive list.

Success paths: 204 versus 202

The endpoint waits for the change, so a completed removal returns 204 with an empty body. If the write is still running, or finished but its result cannot be read back yet, the response is 202 with an operation object containing id, status and url; the Location header carries the same URL. Poll that URL until status is SUCCEEDED or FAILED. A status of UNKNOWN means no result arrived within 15 minutes, and the change may or may not have been applied, so read the user to check. A late result can still move the operation to SUCCEEDED or FAILED. The 202 body shape is fixed in the supplied contract module (code0002, schema0007).

Side effect: keys and webhooks are revoked

Narrowing the user's reach has a downstream consequence. Their API keys and webhooks are revoked within about 60 seconds of the role removal. If an integration depends on that user's credentials, plan the cutover before you call the endpoint rather than after. This is a documented behavior of the role change, not a separate cleanup step you trigger.

Retry safety with Idempotency-Key

The optional Idempotency-Key header accepts 1 to 255 printable ASCII characters and is retained for 24 hours per API key. Repeating the same key with the same request inside that window replays the original response and adds the Idempotent-Replayed header. Three failure modes are worth knowing: reusing the key for a different request returns 422 IDEMPOTENCY_KEY_REUSED; retrying while the first attempt is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; and a malformed key returns 400 INVALID_IDEMPOTENCY_KEY. The full header contract is in schema0002 and schema0005.

Telling the failures apart

Several errors look similar but mean different things. Use this as a triage list:

  • 403 ON_BEHALF_OF_NOT_ALLOWED — the acting user is not permitted for this write; check the users:act-on-behalf scope and that the key owner manages the target user.
  • 403 FORBIDDEN — the key owner's role does not cover this action.
  • 404 RESOURCE_NOT_FOUND — the user does not exist or is outside the key's data reach.
  • 404 ROLE_NOT_FOUND — the Location Admin role itself cannot be found.
  • 409 LAST_ADMIN_CANNOT_BE_REMOVED — the change would leave the company without an admin.
  • 422 IDEMPOTENCY_KEY_REUSED — the key was used with a different request.
  • 409 IDEMPOTENCY_REQUEST_IN_PROGRESS — the first request is still running.
  • 400 INVALID_IDEMPOTENCY_KEY — the key is malformed.

The generic error envelope used across the API is supplied in schema0008 through schema0015.

Worked example: a 202 that needs polling

Suppose you send the DELETE with a valid key and a fresh Idempotency-Key, and the response is 202 with an operation whose status is PENDING and whose url is /v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93. Your client should read the Location header (same URL) and poll it on a backoff until status becomes SUCCEEDED or FAILED. If you instead get 204, there is nothing to poll and the removal is done. If polling returns UNKNOWN after 15 minutes, do not assume success: fetch the user and inspect their roles before retrying. The exact 202 payload is preserved in code0002.

Pre-flight checklist

Before you call the endpoint, confirm each of these:

  1. The key carries users:write, and if you use X-On-Behalf-Of, it also carries users:act-on-behalf.
  2. The key owner is an admin, or a location admin who manages all of the target user's managed locations.
  3. Removing this user will not leave the company without an admin (otherwise expect 409 LAST_ADMIN_CANNOT_BE_REMOVED).
  4. Any integration relying on this user's API keys or webhooks has a replacement plan, because those are revoked within about 60 seconds.
  5. You have a stable Idempotency-Key ready if the call may be retried.
  6. Your client handles both 204 (done) and 202 (poll the operation URL).
Response triage for the Location Admin removal call
StatusMeaningWhat to do
204Removal completed; empty bodyTreat as done; no polling
202Operation still running or result not readable yetPoll operation.url until SUCCEEDED or FAILED
403 ON_BEHALF_OF_NOT_ALLOWEDActing user not permittedCheck users:act-on-behalf and key-owner management of the target user
403 FORBIDDENKey owner's role does not cover the actionUse an admin or qualifying location admin key
404 RESOURCE_NOT_FOUNDUser missing or outside key's data reachVerify the user ID and key scope
404 ROLE_NOT_FOUNDLocation Admin role not foundConfirm the user currently holds the role
409 LAST_ADMIN_CANNOT_BE_REMOVEDWould leave company without an adminAssign another admin first
422 IDEMPOTENCY_KEY_REUSEDKey reused with a different requestUse a fresh key for the new request
409 IDEMPOTENCY_REQUEST_IN_PROGRESSFirst request still runningWait and retry with the same key
400 INVALID_IDEMPOTENCY_KEYMalformed keyUse 1–255 printable ASCII characters

Codes and statuses reflect the supplied API contract; behavior of your own client retry logic is your responsibility.

Frequently asked questions

Does the user lose their regular role too?

No. Only the Location Admin role is removed. The user's ordinary role stays, and Admin status stays if they already had it.

Does this remove Location Admin from just one location?

It removes the role for all the locations the user manages. There is no per-location variant described in this contract.

Why did I get 409 LAST_ADMIN_CANNOT_BE_REMOVED?

The change would leave the company with no admin. Promote or assign another admin before retrying the removal.

Will the user's API keys and webhooks keep working?

No. They are revoked within about 60 seconds of the role removal, so plan any dependent integration cutover in advance.

What does an operation status of UNKNOWN mean?

No result arrived within 15 minutes. The change may or may not have been applied, so read the user to check rather than assuming success. A later result can still resolve the operation to SUCCEEDED or FAILED.

How do I give the role back?

Use the companion endpoint that makes a user a Location Admin. Its locationIds field is the full list of locations the user should manage after the call, not a list to add.

curl -X DELETE "$API_BASE_URL/v2/users/string/location-admin" \
  -H "Authorization: Bearer "
{
  "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.

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