Use this endpoint to add a new location, optionally moving users into it, marking it as the company default, and setting its starting work week. Only name and timezone are mandatory; the remaining fields have documented defaults, so a minimal request is enough for a standard Monday-to-Friday setup.
Before you call
Send a POST request to /v2/locations with a JSON body. Authorization uses a Bearer API key carrying the locations:write scope. The acting user is normally the key owner; setting X-On-Behalf-Of changes that to the named user, which requires the users:act-on-behalf scope and a managed relationship with that user. Add an Idempotency-Key whenever a retry is possible, because it makes the write safe to repeat.
Required and optional fields
Provide name (surrounding spaces are trimmed) and timezone as an IANA name such as America/Los_Angeles. Everything else is optional: firstDayOfWeek defaults to 1 for Monday, resetQuotas to FISCAL_YEAR, yearStartMonth and yearStartDay to 1, isDefault to false, and userIds to an empty list. Note that yearStartDay must be valid in yearStartMonth in every year, so 29 February is rejected. Unknown fields or out-of-range values fail validation.
Moving users, defaults, and the work week
Listing userIds moves those users into the new location, and isDefault set to true makes it the company default. The workWeek object sets the initial schedule; if you omit it, the location starts with Monday to Friday and default work hours. A practical checklist before sending: confirm the name is not already used, check that every user ID exists, verify the fiscal-year start date is valid every year, and confirm your plan allows any custom work hours you include.
Reading the result and handling errors
A 201 response returns the finished location, including its id, name, timezone, isDefault flag, and createdAt timestamp. A 202 response instead returns an operation with an id, status, and url; poll that URL until the status becomes SUCCEEDED or FAILED. Treat UNKNOWN as undecided: read the location back to see whether the change was applied. Errors use a shared envelope with code, name, description, resolution, and requestId; common cases include 400 VALIDATION_ERROR with details.fields, 403 FORBIDDEN, 409 DUPLICATE_NAME, 422 UNKNOWN_USER_IDS, and 422 PLAN_LIMIT_REACHED.
Create-location request fields
Field
Required
Default or rule
name
Yes
Trimmed; must not be empty
timezone
Yes
IANA time zone name
firstDayOfWeek
No
1 (Monday); range 0-6
resetQuotas
No
FISCAL_YEAR or USER_YEAR
yearStartMonth / yearStartDay
No
1 / 1; day must exist every year
isDefault
No
false
userIds
No
Empty array; listed users move in
workWeek
No
Monday-Friday with default work hours
Defaults apply when the field is omitted; unknown fields fail validation.
Response and error handling
Status
Meaning
Next step
201
Location created and returned
Use the returned location id
202
Still running beyond the wait window
Poll the operation URL
400
Validation or invalid body
Fix fields listed in details.fields
403
Forbidden or on-behalf not allowed
Check scope and acting-user permissions
409
Duplicate name or idempotency in progress
Read current state, then retry
422
Unknown user IDs or plan limit
Correct user IDs or plan
Poll the operation URL for 202 until SUCCEEDED or FAILED; UNKNOWN means check the resource.
Frequently asked questions
Who is treated as acting when I create a location?
Send the request with a Bearer API key that carries locations:write. If you also set X-On-Behalf-Of, that user becomes the acting user; the key owner must manage that user and hold users:act-on-behalf, otherwise the call is rejected with 403 ON_BEHALF_OF_NOT_ALLOWED.
What is the difference between a 201 and a 202 response?
A 201 response returns the created location. A 202 response means creation was still running beyond the wait window, so poll the returned operation URL until it reports SUCCEEDED or FAILED.
How should I retry a failed location creation safely?
Use a stable Idempotency-Key for retries. Repeating the same key with the same payload within 24 hours replays the original response; using that key for a different payload returns 422 IDEMPOTENCY_KEY_REUSED, and retrying while the first attempt is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS.
{
"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": "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"
}
}
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.
response
Field
Type
Required
Description
Constraints
response
object
response.data
object
Yes
response.data.id
string
Yes
location ID
response.data.name
string
Yes
location name
response.data.timezone
string
No
the location's IANA time zone, left out when none is stored
response.data.isDefault
boolean
Yes
whether this is the company's default location
response.data.createdAt
string
Yes
a timestamp in the ISO 8601 format
Format: date-time
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.
"PENDING" | "SUCCEEDED" | "FAILED" | "UNKNOWN"
response.operation.url
string
Yes
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code
response.error.details.[key: string]
any
No
response
Field
Type
Required
Description
Constraints
response
object
Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.error
object
Yes
response.error.code
string
Yes
stable machine-readable error code
response.error.name
string
Yes
short human-readable error name
response.error.description
string
Yes
what went wrong
response.error.resolution
string
Yes
how to fix the problem
response.error.requestId
string
Yes
request ID, include it when contacting support
response.error.details
object
No
optional additional information specific to the error code