[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fservice\u002Fdepartment":3,"docs-tabs-chats\u002Fservice\u002Fdepartment":6},{"content":4,"lastmod":5},"## User department\n\n`GET \u002Fv1\u002Fchats\u002Fusers\u002F:userId\u002Fdepartment`\n\nReturns the lowest department the user belongs to in the company structure, by user ID or for the key owner.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|----------|\n| `userId` (path) | string | yes | User ID — a positive integer from the [user list](\u002Fdocs\u002Fentities\u002Fusers\u002Flist), or `me` for the key owner |\n\nThere are no query parameters: any parameter is rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fusers\u002Fme\u002Fdepartment\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\"\n```\n\n### curl — OAuth application\n\n```bash\ncurl \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fusers\u002F4\u002Fdepartment\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\"\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fusers\u002Fme\u002Fdepartment', {\n  headers: { 'X-Api-Key': 'YOUR_API_KEY' },\n})\n\nconst { data } = await res.json()\nconsole.log('My department:', data.name)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fusers\u002F4\u002Fdepartment', {\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n  },\n})\n\nconst { data } = await res.json()\nconsole.log('Department:', data.id, data.name)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data` | object | The user's department |\n| `data.id` | number \\| null | Department ID — a node of the company structure, as in [org structure nodes](\u002Fdocs\u002Fhumanresources\u002Fnodes). `null` — the user is not in any department |\n| `data.name` | string \\| null | Department name |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": { \"id\": 1, \"name\": \"Sales\" }\n}\n```\n\n## Error response example\n\n422 — the user was not found:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"USER_NOT_FOUND\",\n    \"b24Code\": \"USER_NOT_FOUND\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `userId` is neither a positive integer nor `me`, or a query parameter was passed |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error, and the Bitrix24 code is in `error.b24Code`. `USER_NOT_FOUND` — the user does not exist |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | Failed to resolve the key owner for `me` |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or returned a server error |\n\nThe full list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## See also\n\n- [Employees](\u002Fdocs\u002Fentities\u002Fusers)\n- [Org structure nodes](\u002Fdocs\u002Fhumanresources\u002Fnodes)\n- [Service methods](\u002Fdocs\u002Fchats\u002Fservice)\n","2026-10-07",{},1794739551581]