# Invite user (v2) Invite a user to an organization with role and department assignments in a single call. Invites a user to the specified organization. If the user already exists globally (by email), they are added to the organization. If not, a new user account is created. You can assign roles and departments in the same request. #### Path Parameters **`organization_id`** string required The unique identifier of the organization (format: `org_*`). #### Request Body **`email`** string required The email address of the user to invite. **`full_name`** string optional The full name of the user. Max 255 characters. **`role_ids`** array of strings optional · Defaults to `[]` List of role IDs to assign to the user (format: `role_*`). **`department_ids`** array of strings optional · Defaults to `[]` List of department IDs to assign the user to (format: `dept_*`). **`send_invitation`** boolean optional · Defaults to `true` Whether to send an invitation email to the user. **`custom_message`** string optional Custom message to include in the invitation email. ## Returns The user object with their role and department assignments, with a `201 Created` status code. Request ```bash cURL curl -X POST https://api.aitronos.com/v1/organizations/org_xyz789/users/invite/v2 \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "jane@example.com", "full_name": "Jane Doe", "role_ids": ["role_abc123"], "department_ids": ["dept_eng001"], "send_invitation": true }' ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") # Users V2 endpoints coming to SDK soon # result = client.users.invite_v2( # organization_id="org_xyz789", # email="jane@example.com", # full_name="Jane Doe", # role_ids=["role_abc123"], # department_ids=["dept_eng001"], # ) ``` ```python Python import requests org_id = "org_xyz789" url = f"https://api.aitronos.com/v1/organizations/{org_id}/users/invite/v2" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", } data = { "email": "jane@example.com", "full_name": "Jane Doe", "role_ids": ["role_abc123"], "department_ids": ["dept_eng001"], "send_invitation": True, } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` ```javascript JavaScript const orgId = "org_xyz789"; const response = await fetch( `https://api.aitronos.com/v1/organizations/${orgId}/users/invite/v2`, { method: "POST", headers: { Authorization: "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", }, body: JSON.stringify({ email: "jane@example.com", full_name: "Jane Doe", role_ids: ["role_abc123"], department_ids: ["dept_eng001"], send_invitation: true, }), } ); const data = await response.json(); console.log(data); ``` Response ```json 201 Created { "id": "usr_abc123def456", "full_name": "Jane Doe", "email": "jane@example.com", "user_name": null, "account_state": "pending_invitation", "role_ids": ["role_abc123"], "department_ids": ["dept_eng001"], "organization_id": "org_xyz789", "invitation_link": null, "invited_at": "2025-12-22T15:30:00", "deactivated_at": null } ``` ```json 409 Conflict { "success": false, "error": { "code": "USER_ALREADY_EXISTS", "message": "An account with this email already exists.", "system_message": "an account with this email already exists.", "type": "client_error", "status": 409, "details": { "email": "jane@example.com", "organization_id": "org_xyz789" }, "trace_id": "abc-123-def", "timestamp": "2025-12-22T15:30:00Z" } } ``` ## Related Resources - [Update memberships](/docs/api-reference/users/update-memberships) - [Deactivate user](/docs/api-reference/users/deactivate) - [Reactivate user](/docs/api-reference/users/reactivate) - [Remove user](/docs/api-reference/users/remove)