List locations with the REST API v2 endpoint
Use this endpoint when you need a complete inventory of the locations your API key can reach. It is a read-only GET request: send no body, and expect the full list back in a single JSON response rather than a paginated sequence.
What to check before you call
Before calling, confirm three things: the request uses GET, the Authorization header carries the full Bearer token, and the key includes the locations:read scope. The key owner's role then controls visibility. An admin key returns the whole location set; a location-admin key returns only managed locations. If your result looks smaller than expected, check the role before assuming locations are missing.
Reading the response
A successful 200 response wraps the locations in a data array. Each entry can be read as follows:
- id: the stable location identifier to use in later calls
- name: the display name of the location
- timezone: the IANA time zone, present only when one is stored
- isDefault: whether this is the company's default location
- createdAt: the creation timestamp in ISO 8601 format
A practical example: if the array contains a Belgrade entry marked as default and a Los Angeles entry that is not, treat the first as the fallback location and use each id explicitly when a later operation needs a specific site, rather than relying on ordering.
Distinguishing failures
Failures use a shared error envelope with a machine-readable code, a short name, a description, a suggested resolution and a requestId. Keep these cases separate when debugging:
- 401 UNAUTHORIZED: the key is missing, malformed, unrecognized or revoked, so fix the Authorization header first
- 403 INSUFFICIENT_SCOPE: the key is valid but lacks a required scope, so compare details.requiredScopes with the key's scopes
- 429 RATE_LIMITED: too many requests arrived in a short window, so wait a few seconds and retry
- 500 INTERNAL_ERROR: the problem is server-side, so retry later and quote the requestId if it continues
Do not treat a 403 scope problem as a bad token, and do not treat a 429 as a permissions problem; the code tells you which fix applies.
Pre-flight checklist
Use this as a pre-flight checklist:
- Confirm the method is GET and no request body is sent
- Confirm the Authorization header uses Bearer followed by the full key
- Confirm the key carries locations:read
- Confirm whether the key owner is an admin or a location admin, and expect the result set to match that role
- On success, read locations from the data array and note that timezone may be absent
- On failure, branch on the error code and preserve the requestId for support
When you need to add a site after listing, the neighbouring create-location operation is the natural next step; when you need to remove a department, that operation sits in a different reference section.
Frequently asked questions
Do I need to paginate through locations?
No. The complete set reachable by your key is returned together, so there is no page-by-page collection step to manage.
What determines which locations I receive?
The key must carry locations:read and be sent as a Bearer token. What you receive then depends on the key owner's role: admins receive all locations, while location admins receive only the locations they manage.
How do I distinguish the main failures?
Check the error code and name first. UNAUTHORIZED points to a missing, malformed, unrecognized or revoked key; INSUFFICIENT_SCOPE points to a missing scope; RATE_LIMITED means waiting briefly before retrying; INTERNAL_ERROR means retrying later and quoting the requestId if it persists.
curl -X GET "$API_BASE_URL/v2/locations" \
-H "Authorization: Bearer "{
"data": [
{
"id": "location-6ca89536-be55-42c5-8e52-c5c4215afb9f",
"name": "Belgrade",
"timezone": "Europe/Belgrade",
"isDefault": true,
"createdAt": "2021-03-15T08:00:00.000Z"
},
{
"id": "location-79c77ac8-e5bf-479f-9488-648a58379ff1",
"name": "Los Angeles",
"timezone": "America/Los_Angeles",
"isDefault": false,
"createdAt": "2022-08-22T15:00:00.000Z"
}
]
}{
"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": "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"
}
}response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | |||
| response.data | array<Location> | Yes | ||
| response.data[] | object | |||
| 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 | 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 |