Skip to content

Delete a location

This endpoint removes a non-default location from the company. It requires the locations:write scope and sends no request body. The acting user is either the API key owner or the user named in X-On-Behalf-Of. The call either finishes immediately with 204 or returns 202 Accepted with an operation you poll until it reaches a terminal status.

What deletion actually changes

Two effects matter before you send the request. First, the company's default location is protected: it can never be deleted, so make another location the default first. Second, deleting any other location reassigns all of its users to the default location and removes the location's holidays. Treat the call as a data migration, not just a record removal, and confirm the default location is the one you want to receive those users.

Request shape and controls

The method is DELETE against /v2/locations/{id}. The only path parameter is id, a required string resource ID. There is no request body. Two optional headers change behavior: Idempotency-Key makes the write safe to retry, and X-On-Behalf-Of sets the user the write is performed for. The complete request and response contracts, including the exact cURL example and the accepted-operation JSON, accompany this page as protected modules; use them as the source of truth for field names and payload shape.

Pre-flight checklist

Run through these before sending:

  • Confirm the target location is not the company default. If it is, promote another location first; otherwise the request returns 409 DEFAULT_LOCATION_DELETE_FORBIDDEN.
  • Confirm the API key carries locations:write.
  • If acting for another user, confirm the key also has users:act-on-behalf and that the key owner manages that user, or expect 403 ON_BEHALF_OF_NOT_ALLOWED.
  • Decide whether to send Idempotency-Key. If you do, keep it between 1 and 255 printable ASCII characters and reuse the same key only for the identical request.
  • Note which location is currently default, because users from the deleted location will move there.

Telling the failures apart

The status codes point at different fixes, so do not collapse them into one retry path:

  • 403 ON_BEHALF_OF_NOT_ALLOWED: the acting-user header is not permitted for this key or target.
  • 403 FORBIDDEN: the key or acting user lacks permission for the action.
  • 404 RESOURCE_NOT_FOUND: the location does not exist or sits outside the key's data reach.
  • 409 DEFAULT_LOCATION_DELETE_FORBIDDEN: the location is the default and must be replaced before deletion.
  • 409 IDEMPOTENCY_REQUEST_IN_PROGRESS: the first request with this key is still running.
  • 422 IDEMPOTENCY_KEY_REUSED: the key was already used with a different request.
  • 400 INVALID_IDEMPOTENCY_KEY: the key fails the length or character rule.

A 404 is not proof the location was never created; it can also mean the key cannot see it.

Handling 204 versus 202

A 204 means the deletion is complete and the response body is empty. A 202 means the write is still running, or succeeded but its result could not be read back yet; the body carries an operation object with id, status, and url, and the Location header repeats that URL. Poll the operation URL until status is SUCCEEDED or FAILED. If status is UNKNOWN, no result arrived within 15 minutes and the change may or may not have been applied, so read the location resource to check rather than assuming success. A result that arrives later still moves the status to SUCCEEDED or FAILED.

Retry behavior with Idempotency-Key

Think of the key as a receipt number for one specific write. Each key is stored for 24 hours against the API key that sent it, and within that window an identical repeat does not run the deletion again: the service returns the stored response and marks it with the Idempotent-Replayed header. The key is tied to the request it was first used with, so pointing the same key at a different request is rejected with 422 IDEMPOTENCY_KEY_REUSED. If the original call has not finished yet, a second attempt under that key is refused with 409 IDEMPOTENCY_REQUEST_IN_PROGRESS rather than starting a parallel delete. A key that breaks the 1–255 printable ASCII rule fails with 400 INVALID_IDEMPOTENCY_KEY. In practice, mint one key per intended deletion and reuse it only for that deletion.

Worked example

Suppose a company has a default location in London and a secondary office in Berlin. You want to remove Berlin. Because Berlin is not the default, the request is allowed. Sending DELETE /v2/locations/{berlin-id} with locations:write returns 204, and every Berlin user now belongs to London while Berlin's holidays are gone. If instead you target London, the response is 409 DEFAULT_LOCATION_DELETE_FORBIDDEN and nothing changes. If you retry the Berlin delete with the same Idempotency-Key after a timeout, the original 204 is replayed with Idempotent-Replayed rather than a second deletion attempt.

Frequently asked questions

Can the default location be deleted?

No. The company's default location can never be deleted. Make another location the default first; otherwise the request returns 409 DEFAULT_LOCATION_DELETE_FORBIDDEN.

What happens to users and holidays when a location is deleted?

All users of the deleted location are moved to the default location, and the location's holidays are deleted.

Why did I get 202 instead of 204?

204 means the deletion finished and the body is empty. 202 means the write is still running, or succeeded but its result could not be read back yet. The 202 body contains an operation with id, status, and url; poll that URL until status is SUCCEEDED or FAILED.

What does an UNKNOWN operation status mean?

UNKNOWN means no result arrived within 15 minutes. The change may or may not have been applied, so read the location resource to check. A result that arrives later still changes the status to SUCCEEDED or FAILED.

Does 404 mean the location never existed?

Not necessarily. RESOURCE_NOT_FOUND means the location does not exist or is outside the key's data reach. Check the ID and confirm the key owner can see the location.

Can I reuse an Idempotency-Key for a different delete?

No. Reusing the key with a different request returns 422 IDEMPOTENCY_KEY_REUSED. Use one key per intended deletion and reuse it only for the identical request.

curl -X DELETE "$API_BASE_URL/v2/locations/string" \
  -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