# Get department tree Retrieve the full hierarchical tree of departments within an organization. Returns a nested tree structure of all departments in the organization. Each node includes its children as a nested array, allowing you to render the full hierarchy in a single request. Optionally scope the tree to specific departments and their descendants. #### Path Parameters **`organization_id`** string required The unique identifier of the organization (format: `org_*`). #### Query Parameters **`scope`** string optional Comma-separated list of department IDs to scope the tree. When provided, only the specified departments and their descendants are returned. ## Returns An array of department tree objects. Each object contains the standard department fields plus a `children` array with nested department tree objects. Request ```bash cURL curl https://api.aitronos.com/v1/organizations/org_xyz789/departments/tree \ -H "Authorization: Bearer $ACCESS_TOKEN" ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") # Department endpoints coming to SDK soon # result = client.departments.tree(organization_id="org_xyz789") ``` ```python Python import requests org_id = "org_xyz789" url = f"https://api.aitronos.com/v1/organizations/{org_id}/departments/tree" headers = {"Authorization": "Bearer YOUR_ACCESS_TOKEN"} response = requests.get(url, headers=headers) tree = response.json() print(tree) ``` ```javascript JavaScript const orgId = "org_xyz789"; const response = await fetch( `https://api.aitronos.com/v1/organizations/${orgId}/departments/tree`, { headers: { "Authorization": `Bearer ${accessToken}` }, } ); const tree = await response.json(); console.log(tree); ``` Response ```json 200 OK [ { "id": "dept_abc123", "name": "Engineering", "description": "Software development team", "parent_id": null, "path": "/dept_abc123", "depth": 0, "organization_id": "org_xyz789", "member_count": 5, "is_active": true, "is_default": false, "color": null, "created_by": "usr_owner1", "created_at": "2025-01-15T10:00:00Z", "children": [ { "id": "dept_def456", "name": "Backend", "description": "Backend engineering team", "parent_id": "dept_abc123", "path": "/dept_abc123/dept_def456", "depth": 1, "organization_id": "org_xyz789", "member_count": 3, "is_active": true, "is_default": false, "color": null, "created_by": "usr_owner1", "created_at": "2025-01-16T14:30:00Z", "children": [] } ] }, { "id": "dept_ghi789", "name": "Marketing", "description": "Marketing and communications", "parent_id": null, "path": "/dept_ghi789", "depth": 0, "organization_id": "org_xyz789", "member_count": 2, "is_active": true, "is_default": false, "color": null, "created_by": "usr_owner1", "created_at": "2025-01-17T09:00:00Z", "children": [] } ] ``` ```json 404 Error { "success": false, "error": { "code": "ORGANIZATION_NOT_FOUND", "message": "The requested organization could not be found.", "system_message": "Organization not found", "type": "client_error", "status": 404, "details": { "organization_id": "org_invalid" }, "trace_id": "abc-123-def", "timestamp": "2025-11-02T08:21:45Z" } } ``` ## Related Resources - [List Departments](/docs/api-reference/departments/list) - [Retrieve Department](/docs/api-reference/departments/retrieve) - [Create Department](/docs/api-reference/departments/create) - [Update Department](/docs/api-reference/departments/update) - [Reparent Department](/docs/api-reference/departments/reparent) - [Delete Department](/docs/api-reference/departments/delete) - [List Department Members](/docs/api-reference/departments/list-members) - [Add Department Member](/docs/api-reference/departments/add-member) - [Remove Department Member](/docs/api-reference/departments/remove-member) - [Department Object](/docs/api-reference/objects/department-object)