# Create department Create a new department within an organization. Creates a new department in the specified organization. You can optionally place it under an existing parent department to build a hierarchy. The department name must be unique within the organization. #### Path Parameters **`organization_id`** string required The unique identifier of the organization (format: `org_*`). #### Request Body **`name`** string required The name of the department. Must be between 1 and 255 characters. **`description`** string optional A description of the department's purpose and responsibilities. **`parent_id`** string | null optional The ID of the parent department (format: `dept_*`). If omitted or `null`, the department is created as a top-level department. ## Returns The newly created department object with a `201 Created` status code. Request ```bash cURL curl -X POST https://api.aitronos.com/v1/organizations/org_xyz789/departments \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "Backend", "description": "Backend engineering team", "parent_id": "dept_abc123" }' ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") # Department endpoints coming to SDK soon # result = client.departments.create( # organization_id="org_xyz789", # name="Backend", # description="Backend engineering team", # parent_id="dept_abc123", # ) ``` ```python Python import requests org_id = "org_xyz789" url = f"https://api.aitronos.com/v1/organizations/{org_id}/departments" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", } data = { "name": "Backend", "description": "Backend engineering team", "parent_id": "dept_abc123", } response = requests.post(url, headers=headers, json=data) department = response.json() print(department) ``` ```javascript JavaScript const orgId = "org_xyz789"; const response = await fetch( `https://api.aitronos.com/v1/organizations/${orgId}/departments`, { method: "POST", headers: { "Authorization": `Bearer ${accessToken}`, "Content-Type": "application/json", }, body: JSON.stringify({ name: "Backend", description: "Backend engineering team", parent_id: "dept_abc123", }), } ); const department = await response.json(); console.log(department); ``` Response ```json 201 Created { "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": 0, "is_active": true, "is_default": false, "color": null, "created_by": "usr_owner1", "created_at": "2025-01-16T14:30:00Z" } ``` ```json 409 Error { "success": false, "error": { "code": "DEPARTMENT_NAME_CONFLICT", "message": "A department with this name already exists in the organization.", "system_message": "Department name conflict", "type": "client_error", "status": 409, "details": { "name": "Backend" }, "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) - [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)