## Department list

`GET /v1/departments`

Returns the list of departments in your Bitrix24 account with support for filtering and field selection.

## Parameters

| Parameter | Type | Default | Description |
|----------|-----|-----------|---------|
| `limit` | number | `50` | Number of records (up to 5000). When `limit > 50` the request is automatically assembled from several pages on the server side |
| `offset` | number | `0` | Number of records to skip: `offset=7` starts the selection at the 8th department |
| `select` | string | — | Field selection: `?select=id,name`. Only the listed fields are returned |
| `filter` | object | — | Only exact equality and `$in` (IN-set) on the fields `id`, `name`, `parentId`, `headId`. Operators (`>`, `>=`, `<`, `<=`, `!`, `%`, `$ne`, `$contains`, `$nin`) and other fields are not supported — a `400 UNSUPPORTED_FILTER` is returned.<br>[Filtering syntax](/docs/filtering). Example: `?filter[parentId]=1` |

## Examples

### curl — personal key

```bash
curl -g "https://vibecode.bitrix24.com/v1/departments?filter[parentId]=1" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -g "https://vibecode.bitrix24.com/v1/departments?filter[parentId]=1" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/departments?filter[parentId]=1', {
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success, data, meta } = await res.json()
console.log(`Found ${meta.total} departments`)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/departments?filter[parentId]=1', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

const { success, data, meta } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | Array of departments (see [Department fields](/docs/entities/departments/fields)) |
| `meta.total` | number | Total number of records matching the filter. Present in every response |
| `meta.hasMore` | boolean | Whether there are more records beyond `limit` |

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 47,
      "name": "Sales department",
      "sort": 500,
      "parentId": 1,
      "headId": 99
    },
    {
      "id": 107,
      "name": "Development department",
      "sort": 600,
      "parentId": 1,
      "headId": 1
    }
  ],
  "meta": {
    "total": 2,
    "hasMore": false
  }
}
```

## Error response example

400 — an operator or an unsupported field in the filter:

```json
{
  "success": false,
  "error": {
    "code": "UNSUPPORTED_FILTER",
    "message": "UNSUPPORTED_FILTER: 'sort' is not filterable on 'departments'. Its Bitrix24 method (department.get) filters by exact match only. Filterable: id, name, parentId, headId."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNSUPPORTED_FILTER` | An operator or an unsupported field in the filter. Filter by exact equality or `$in` on `id`, `name`, `parentId`, `headId` |
| 400 | `INVALID_SORT_FIELD` | The `order` or `sort` parameter was passed — departments cannot be sorted |
| 403 | `SCOPE_DENIED` | The API key does not have the `department` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 429 | `RATE_LIMITED` | Rate limit exceeded: 300 requests per minute per portal. All API keys of the portal share one limit. The current limit is returned in the `x-ratelimit-limit` header. Retry after the delay in the `Retry-After` header |

For the full list of common API errors, see [Errors](/docs/errors).

## Known specifics

**The Bitrix24 account sets the record order.** The API cannot sort the selection. To get departments in a specific order, load all records matching the filter and sort them on the client side. With `limit` up to 5000, the whole list arrives in a single request.

**Conditions in the request body.** The same filters can be passed in the body of [`POST /v1/departments/search`](./search.md) instead of the query string.

## See also

- [Department search](/docs/entities/departments/search)
- [Get department](/docs/entities/departments/get)
- [Create department](/docs/entities/departments/create)
- [Filtering syntax](/docs/filtering)
- [Entity API](/docs/entity-api)
- [Batch](/docs/batch)
