# Update memberships Update a user's role and department assignments within an organization. Replaces the user's current role and department assignments with the provided lists. Roles and departments not in the new lists are removed; new ones are added. #### Path Parameters **`organization_id`** string required The unique identifier of the organization (format: `org_*`). **`user_id`** string required The unique identifier of the user (format: `usr_*`). #### Request Body **`role_ids`** array of strings required The complete list of role IDs the user should have (format: `role_*`). **`department_ids`** array of strings required The complete list of department IDs the user should belong to (format: `dept_*`). ## Returns The updated user object with the new role and department assignments. Request ```bash cURL curl -X PATCH https://api.aitronos.com/v1/organizations/org_xyz789/users/usr_abc123/memberships \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "role_ids": ["role_admin1", "role_member1"], "department_ids": ["dept_eng001", "dept_design001"] }' ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") # Users V2 endpoints coming to SDK soon # result = client.users.update_memberships( # organization_id="org_xyz789", # user_id="usr_abc123", # role_ids=["role_admin1", "role_member1"], # department_ids=["dept_eng001", "dept_design001"], # ) ``` ```python Python import requests org_id = "org_xyz789" user_id = "usr_abc123" url = f"https://api.aitronos.com/v1/organizations/{org_id}/users/{user_id}/memberships" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", } data = { "role_ids": ["role_admin1", "role_member1"], "department_ids": ["dept_eng001", "dept_design001"], } response = requests.patch(url, headers=headers, json=data) print(response.json()) ``` ```javascript JavaScript const orgId = "org_xyz789"; const userId = "usr_abc123"; const response = await fetch( `https://api.aitronos.com/v1/organizations/${orgId}/users/${userId}/memberships`, { method: "PATCH", headers: { Authorization: "Bearer YOUR_ACCESS_TOKEN", "Content-Type": "application/json", }, body: JSON.stringify({ role_ids: ["role_admin1", "role_member1"], department_ids: ["dept_eng001", "dept_design001"], }), } ); const data = await response.json(); console.log(data); ``` Response ```json 200 OK { "id": "usr_abc123", "full_name": "Jane Doe", "email": "jane@example.com", "user_name": "janedoe", "account_state": "active", "role_ids": ["role_admin1", "role_member1"], "department_ids": ["dept_eng001", "dept_design001"], "organization_id": "org_xyz789", "invitation_link": null, "invited_at": null, "deactivated_at": null } ``` ```json 404 Not Found { "success": false, "error": { "code": "MEMBER_NOT_FOUND", "message": "The specified member could not be found.", "system_message": "the specified member could not be found.", "type": "client_error", "status": 404, "details": { "user_id": "usr_abc123", "organization_id": "org_xyz789" }, "trace_id": "abc-123-def", "timestamp": "2025-12-22T15:30:00Z" } } ``` ## Related Resources - [Invite user (v2)](/docs/api-reference/users/invite-v2) - [Deactivate user](/docs/api-reference/users/deactivate) - [Reactivate user](/docs/api-reference/users/reactivate) - [Remove user](/docs/api-reference/users/remove)