Skip to content

List Departments with GET /v2/departments

The list departments endpoint returns every department the API key can reach in a single response. There is no pagination, so you receive the full set at once. The call requires the departments:read scope and a bearer token. What you see depends on the acting user's role: administrators receive all departments, while other users receive only the departments they manage. Each item carries four fields — id, name, isDefault and createdAt. Parent and approver details are not included here; those appear in the create and update responses.

Endpoint and authorization

Send a GET request to /v2/departments. The Authorization header must carry a bearer token in the form Authorization: Bearer <token>. The key needs the departments:read scope. If the key owner's role is limited, that role further narrows which departments are visible. The endpoint is synchronous and returns the full list without paging parameters.

Response shape

The 200 response is a JSON object with a data array. Each element is a department object with exactly four properties: id (string), name (string), isDefault (boolean indicating the company's default department), and createdAt (ISO 8601 timestamp). No parent or approver fields are present in this list response. The schema module schema0001 defines this contract exactly.

Field map

Use this table to map each returned property to its meaning and type before building a sync or picker.

Error responses

The endpoint can return 401, 403, 429, or 500. A 401 means the key is missing, malformed, or unrecognized. A 403 with INSUFFICIENT_SCOPE means the key lacks departments:read; the error details list the required scopes. A 403 can also mean the acting user may not perform the action. A 429 means too many requests were sent in a short time; wait and retry. A 500 is an internal error; retry later and quote the requestId if it persists. The error envelope is defined in schema0002 through schema0005.

Decision checklist

Before calling list departments, confirm: (1) the key has departments:read; (2) the acting user's role matches the visibility you expect; (3) you need the full list rather than a single department; (4) your code handles the four-field shape without expecting parent or approvers; (5) you have a retry path for 429 and 500. If you need parent or approver data, use the create or update response instead of this list.

Example walkthrough

The captured sample response shows two departments: Operations with isDefault true and createdAt 2021-03-15T08:00:00.000Z, and Dev Team with isDefault false and createdAt 2022-08-22T15:00:00.000Z. Both ids use the team- prefix. A sync job can read this array, match on id, and update local records by name and default flag. Because there is no pagination, the array is complete for the key's reach in one call.

Department list field map
FieldTypeMeaning
idstringdepartment ID
namestringdepartment name
isDefaultbooleanwhether this is the company's default department
createdAtstring (date-time)a timestamp in the ISO 8601 format

Field types and meanings are taken from the supplied response schema. The list response does not include parent or approver fields.

Frequently asked questions

Does the list departments endpoint paginate?

No. It returns every department within the key's data reach in one response, with no pagination parameters.

Why do two users see different department lists?

Administrators see every department. Other users see only the departments they manage. The key owner's role also limits what the key can reach.

Where are parent and approver details?

They are not in the list response. The create and update responses return the department with its parent and approvers.

What does a 403 mean here?

A 403 can mean the key lacks the departments:read scope (INSUFFICIENT_SCOPE, with required scopes in details) or that the acting user may not perform the action. Check the error code to tell them apart.

curl -X GET "$API_BASE_URL/v2/departments" \
  -H "Authorization: Bearer "
{
  "data": [
    {
      "id": "team-969f8429-7dc3-48a1-96b1-6049a99dda06",
      "name": "Operations",
      "isDefault": true,
      "createdAt": "2021-03-15T08:00:00.000Z"
    },
    {
      "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": "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

FieldTypeRequiredDescriptionConstraints
responseobject
response.dataarray<Department>Yes
response.data[]object
response.data[].idstringYesdepartment ID
response.data[].namestringYesdepartment name
response.data[].isDefaultbooleanYeswhether this is the company's default department
response.data[].createdAtstringYesa timestamp in the ISO 8601 formatFormat: date-time

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