Get a department
This reference covers the single-department lookup in REST API v2. The call takes one path parameter and returns the department's ID, name, default flag and creation timestamp. A key must carry the departments:read scope, and the request is sent with a bearer token in the Authorization header.
Request shape and authorization
The endpoint is a GET on /v2/departments/{id}. The only path parameter is id, a required string that identifies the department. Authentication uses a bearer token: the API key travels in the Authorization header as Bearer followed by the vt_live_ key. The key also needs the departments:read scope. How keys are created, which scopes exist and how the key owner's role limits access are covered in the Authentication and Scopes sections of the API documentation.
A practical pre-flight check before sending the request:
- Confirm the key is a full vt_live_ key and is placed in the Authorization header, not a query string.
- Confirm the key has departments:read; a key without it will be rejected rather than returning an empty result.
- Confirm the department ID belongs to data the key owner can see.
- Treat a 404 as either a wrong ID or a record outside the key's data reach, not automatically as a server fault.
Reading the response
A successful call returns a JSON object whose data property holds the department. Four fields are always present:
- id — the department ID, a string.
- name — the department name, a string.
- isDefault — a boolean indicating whether this is the company's default department.
- createdAt — a timestamp in ISO 8601 format.
The sample payload shows a department named Dev Team with isDefault set to false and a creation time of 2022-08-22T15:00:00.000Z. That example is useful for checking how your parser handles a non-default department and a UTC timestamp; it is illustrative data, not a live record.
Telling error states apart
The endpoint can answer with several distinct failures, and the right fix differs for each:
- 401 UNAUTHORIZED — the key is missing, malformed or unrecognized. Send a valid vt_live_ key as a bearer token.
- 403 INSUFFICIENT_SCOPE — the key is valid but lacks a needed scope. Add the scopes listed in details.requiredScopes in the dashboard.
- 403 with a revoked-key or acting-user restriction — the key was revoked, or the acting user may not perform the action.
- 404 RESOURCE_NOT_FOUND — the department does not exist or lies outside the key's data reach. Check the ID and whether the key owner can see the record.
- 429 RATE_LIMITED — too many requests in a short window. Wait briefly and retry; for writes, reuse the same Idempotency-Key.
- 500 INTERNAL_ERROR — a server-side failure. Retry later and quote the requestId if it persists.
Every error envelope carries a stable code, a short name, a description, a resolution hint and a requestId. Include the requestId when escalating to support.
Frequently asked questions
Which scope does the single-department lookup need?
It requires departments:read. A key without that scope receives a 403 INSUFFICIENT_SCOPE error rather than a result.
Does a 404 always mean the department was deleted?
No. The 404 RESOURCE_NOT_FOUND response covers both a department that does not exist and one that sits outside the key's data reach. Verify the ID and the key owner's visibility before concluding the record is gone.
How do I tell whether a department is the company default?
Read the isDefault boolean in the data object. The sample payload shows false for a non-default department.
Where do I send API questions?
Use the developer contact channel listed in the API documentation's support section, and include the requestId from any error envelope.
curl -X GET "$API_BASE_URL/v2/departments/string" \
-H "Authorization: Bearer "{
"data": {
"id": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
"name": "Dev Team",
"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": "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": "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
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| id | string | Yes | resource ID. |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | |||
| response.data | object | Yes | ||
| response.data.id | string | Yes | department ID | |
| response.data.name | string | Yes | department name | |
| response.data.isDefault | boolean | Yes | whether this is the company's default department | |
| 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 |
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 |