# Reparent department Move a department to a new parent or make it a top-level department. Changes the parent of a department, effectively moving it within the hierarchy. The operation updates the department's `parent_id`, `path`, and `depth` fields, as well as those of all its descendants. Circular references (making a department its own ancestor) are rejected. #### Path Parameters **`organization_id`** string required The unique identifier of the organization (format: `org_*`). **`department_id`** string required The unique identifier of the department to move (format: `dept_*`). #### Request Body **`new_parent_id`** string | null required The ID of the new parent department (format: `dept_*`). Set to `null` to make the department a top-level department. ## Returns The updated department object with its new hierarchical position. Request ```bash cURL curl -X POST https://api.aitronos.com/v1/organizations/org_xyz789/departments/dept_def456/reparent \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "new_parent_id": "dept_ghi789" }' ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") # Department endpoints coming to SDK soon # result = client.departments.reparent( # organization_id="org_xyz789", # department_id="dept_def456", # new_parent_id="dept_ghi789", # ) ``` ```python Python import requests org_id = "org_xyz789" dept_id = "dept_def456" url = f"https://api.aitronos.com/v1/organizations/{org_id}/departments/{dept_id}/reparent" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", } data = {"new_parent_id": "dept_ghi789"} response = requests.post(url, headers=headers, json=data) department = response.json() print(department) ``` ```javascript JavaScript const orgId = "org_xyz789"; const deptId = "dept_def456"; const response = await fetch( `https://api.aitronos.com/v1/organizations/${orgId}/departments/${deptId}/reparent`, { method: "POST", headers: { "Authorization": `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ new_parent_id: "dept_ghi789" }), } ); const department = await response.json(); console.log(department); ``` Response ```json 200 OK { "id": "dept_def456", "name": "Backend", "description": "Backend engineering team", "parent_id": "dept_ghi789", "path": "/dept_ghi789/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" } ``` ```json 422 Error { "success": false, "error": { "code": "DEPARTMENT_CYCLE_DETECTED", "message": "This move would create a circular reference in the department hierarchy.", "system_message": "Department cycle detected", "type": "client_error", "status": 422, "details": { "department_id": "dept_def456", "new_parent_id": "dept_ghi789" }, "trace_id": "abc-123-def", "timestamp": "2025-11-02T08:21:45Z" } } ``` ## Related Resources - [Get Department Tree](/docs/api-reference/departments/tree) - [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) - [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)