
## Updating users and groups

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/users-groups/how-tos/update-users-groups

> Update user and group properties in Atlan programmatically using the Python SDK (pyatlan) or Java SDK. Use AtlanUser and AtlanGroup to modify display names, roles, and group membership.

# AtlanGroup: update users and groups

Use `AtlanGroup` in the Atlan Python SDK to programmatically update user and group details in your Atlan environment.

You can update basic properties of both users and groups, again using the builder pattern.

## Update group

For example, to update a group:

### Java

```java showLineNumbers title="Update a group"
AtlanGroup group = AtlanGroup.updater( // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (2)
 "/example_group") // (3)
 .attributes(AtlanGroup.GroupAttributes.builder() // (4)
 .description(List.of("Now with a description!")) // (5)
 .build()) // (6)
 .build(); // (7)
group.update(client); // (8)
```

1. To update a group, start a builder using the `updater()` method.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. You can then specify anything you want to update. In the case of a group, most of the properties are in an embedded `attributes` object that can be built-up through its own builder.
5. For example, you can add or change the description of the group. (Note that all objects in the attributes of a group are lists, even when they only have a single value.)
6. Like other builder patterns, you need to build the attributes object.
7. Like other builder patterns, you need to build the updated group object itself.
8. Finally, you can call the `update()` method on the built-up group object to actually update the group in Atlan. Note that this method doesn't return anything. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Python

```python showLineNumbers title="Update a group"
from pyatlan.model.group import AtlanGroup
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
group = AtlanGroup.create_for_modification( # (1)
 guid="e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", # (2)
 path="/example_group" # (3)
)
group.attributes = AtlanGroup.Attributes( # (4)
 description=["Now with a description!"] # (5)
)
client.group.update(group) # (6)
```

1. To update a group, you could start by retrieving the group. Alternatively, you can use `AtlanGroup.create_for_modification()` to start building a minimal update request.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. You can then specify anything you want to update. In the case of a group, most of the properties are in an embedded `Attributes` class that can be built-up.
5. For example, you can add or change the description of the group. (Note that all objects in the attributes of a group are lists, even when they only have a single value.)
6. Finally, you can call the `group.update()` method with the built-up group object to actually update the group in Atlan. Note that this method doesn't return anything.

### Kotlin

```kotlin showLineNumbers title="Update a group"
val group = AtlanGroup.updater( // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (2)
 "/example_group") // (3)
 .attributes(AtlanGroup.GroupAttributes.builder() // (4)
 .description(listOf("Now with a description!")) // (5)
 .build()) // (6)
 .build() // (7)
group.update(client) // (8)
```

1. To update a group, start a builder using the `updater()` method.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. You can then specify anything you want to update. In the case of a group, most of the properties are in an embedded `attributes` object that can be built-up through its own builder.
5. For example, you can add or change the description of the group. (Note that all objects in the attributes of a group are lists, even when they only have a single value.)
6. Like other builder patterns, you need to build the attributes object.
7. Like other builder patterns, you need to build the updated group object itself.
8. Finally, you can call the `update()` method on the built-up group object to actually update the group in Atlan. Note that this method doesn't return anything. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Go

```go showLineNumbers title="Update a group"
AtlanGroup := assets.AtlanGroup{}
group, atlanErr := AtlanGroup.Updater( // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (2)
 "/example_group", // (3)
)
description := []string{"Now with a description!"}
group.Attributes.Description = description // (4)
ctx.GroupClient.Update(group) // (5)
```

1. To update a group, you could start by retrieving the group. Alternatively, you can use `AtlanGroup.Updater()` to start building a minimal update request.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. You can then specify anything you want to update. In the case of a group, most of the properties are in an embedded `Attributes` class that can be built-up. For example, you can add or change the description of the group. (Note that all objects in the attributes of a group are lists, even when they only have a single value.)
5. Finally, you can call the `GroupClient.Update()` method with the built-up group object to actually update the group in Atlan. Note that this method doesn't return anything.

### Raw REST API

```json showLineNumbers title="POST /api/service/groups/e79cb8eb-2bb6-4821-914c-f8dfd21fedc7"
{
 "id": "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (1)
 "path": "/example_group", // (2)
 "attributes": { // (3)
 "description": [
 "Now with a description!"
 ],
 "isDefault": [
 "false"
 ]
 }
}
```

1. You must provide the GUID of the group within the request payload.
2. You must provide the internal name of the group, prefixed by `/`, as the `path`.
3. You can provide any attributes to update on the group in the `attributes` object.

 :::warning[Values are all arrays of strings]
Note that every value for an attribute is an array of strings, even when there is only a single value.
 :::

### Remove users from group

To remove one or more users from a group:

### Java

```java showLineNumbers title="Remove users from a group"
AtlanGroup group = AtlanGroup.updater( // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (2)
 "/example_group") // (3)
 .build(); // (4)
group.removeUsers(client, List.of("da213751-95de-4f96-8bee-a2c73e2ef8c8")); // (5)
```

1. To update group membership, start a builder using the `updater()` method.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. Like other builder patterns, you need to build the updated group object itself.
5. Use the `removeUsers()` method to remove one or more users from the group. Specify the GUID of each user you want to remove as a member of the group. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Python

```python showLineNumbers title="Remove users from a group"
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
client.group.remove_users( # (1)
 guid="e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", # (2)
 user_ids=["da213751-95de-4f96-8bee-a2c73e2ef8c8"] # (3)
)
```

1. Use the `group.remove_users()` method to remove one or more users from the group.
2. Specify the GUID of the group from which you want to remove users.
3. Specify the GUID of each user you want to remove as a member of the group.

### Kotlin

```kotlin showLineNumbers title="Remove users from a group"
val group = AtlanGroup.updater( // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7", // (2)
 "/example_group") // (3)
 .build() // (4)
group.removeUsers(client, listOf("da213751-95de-4f96-8bee-a2c73e2ef8c8")) // (5)
```

1. To update group membership, start a builder using the `updater()` method.
2. You must provide the GUID of the group...
3. ...and the `path` of the group you want to update. (Note that the path is different from the name—you're best retrieving a group first and then getting the path from that retrieved object if you are unsure.)
4. Like other builder patterns, you need to build the updated group object itself.
5. Use the `removeUsers()` method to remove one or more users from the group. Specify the GUID of each user you want to remove as a member of the group. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Go

```go showLineNumbers title="Remove users from a group"
ctx.GroupClient.RemoveUsers( // (1)
 "a99f50bc-46bf-4d08-a987-3411ef5cfc33", // (2)
 []string{"b060a754-4d16-4e13-b5a8-ba42f10aee39"}, // (3)
)
```

1. Use the `GroupClient.RemoveUsers()` method to remove one or more users from the group.
2. Specify the GUID of the group from which you want to remove users.
3. Specify the GUID of each user you want to remove as a member of the group.

### Raw REST API

```json showLineNumbers title="POST /api/service/groups/e79cb8eb-2bb6-4821-914c-f8dfd21fedc7/members/remove"
{
 "users": [ // (1)
 "da213751-95de-4f96-8bee-a2c73e2ef8c8" // (2)
 ]
}
```

1. You must provide the list of users to remove from the group in a `users` array.
2. Specify each user by its unique ID (GUID).

## Update user

To update a user, begin by building the minimal update object:

### Java

```java showLineNumbers title="Build the minimal update object"
AtlanUser user = AtlanUser.updater( // (1)
 "da213751-95de-4f96-8bee-a2c73e2ef8c8") // (2)
 .build(); // (3)
```

1. To update a user, start a builder using the `updater()` method.
2. You must provide the GUID of the user.
3. Like other builder patterns, you need to build the updated user object itself.

### Python

:::tip[Specific operations below]
The specific operations for updating a user are all listed below - there is no update object to build in the Python SDK.
:::

### Kotlin

```kotlin showLineNumbers title="Build the minimal update object"
val user = AtlanUser.updater( // (1)
 "da213751-95de-4f96-8bee-a2c73e2ef8c8") // (2)
 .build() // (3)
```

1. To update a user, start a builder using the `updater()` method.
2. You must provide the GUID of the user.
3. Like other builder patterns, you need to build the updated user object itself.

### Go

:::tip[Specific operations below]
The specific operations for updating a user are all listed below - there is no update object to build in the Go SDK.
:::

### Raw REST API

:::tip[Implicit in the API calls below]
There is nothing specific to do for this step when using the raw APIs—constructing the object is simply what you place in the payload of the API calls in the steps below.
:::

### Add user to groups

Once you have the update object, to add a user to one or more groups:

### Java

```java title="Add user to groups"
user.addToGroups(client, List.of("e79cb8eb-2bb6-4821-914c-f8dfd21fedc7")); // (1)
```

1. Use the `addToGroups()` method to add the user to one or more groups. Specify the GUID of each group you want to make the user a member of. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Python

```python showLineNumbers title="Add user to groups"
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
client.user.add_to_groups( # (1)
 guid="da213751-95de-4f96-8bee-a2c73e2ef8c8", # (2)
 group_ids=["e79cb8eb-2bb6-4821-914c-f8dfd21fedc7"] # (3)
)
```

1. Use the `user.add_to_groups()` method to add the user to one or more groups.
2. Specify the GUID of the user you want to add to one or more groups.
3. Specify the GUID of each group you want to make the user a member of.

### Kotlin

```kotlin title="Add user to groups"
user.addToGroups(client, listOf("e79cb8eb-2bb6-4821-914c-f8dfd21fedc7")) // (1)
```

1. Use the `addToGroups()` method to add the user to one or more groups. Specify the GUID of each group you want to make the user a member of. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Go

```go showLineNumbers title="Add user to groups"
ctx.UserClient.AddUserToGroups( // (1)
 "b060a754-4d16-4e13-b5a8-ba42f10aee39", // (2)
 []string{"a99f50bc-46bf-4d08-a987-3411ef5cfc33"}, // (3)
)
```

1. Use the `UserClient.AddUserToGroups()` method to add the user to one or more groups.
2. Specify the GUID of the user you want to add to one or more groups.
3. Specify the GUID of each group you want to make the user a member of.

### Raw REST API

```json showLineNumbers title="POST /api/service/users/da213751-95de-4f96-8bee-a2c73e2ef8c8/groups"
{
 "groups": [ // (1)
 "e79cb8eb-2bb6-4821-914c-f8dfd21fedc7" // (2)
 ]
}
```

1. You must provide the list of groups to remove the user from in a `groups` array.
2. Specify each group by its unique ID (GUID).

### Change role of user

Once you have the update object, to change the role of a user:

### Java

```java title="Change role of user"
user.changeRole(client, client.getRoleCache().getIdForName("$guest")); // (1)
```

1. Use the `changeRole()` method to change the role of a user. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::tip[Use the `RoleCache` to find the right GUID]
The `changeRole()` method requires the GUID of the role you want to move the user to. In order to find that GUID, you can use the `RoleCache.getIdForName()` and provide the name of the role.
 :::

### Python

```python showLineNumbers title="Change role of user"
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
client.user.change_role( # (1)
 guid="da213751-95de-4f96-8bee-a2c73e2ef8c8", # (2)
 role_id=client.role_cache.get_id_for_name("$guest") # (3)
)
```

1. Use the `user.change_role()` method to change the role of a user.
2. Specify the GUID of the user whose role you want to change.
3. Specify the GUID of the role you want to change the user to.

 :::tip[Use the `RoleCache` to find the right GUID]
The `user.change_role()` method requires the GUID of the role you want to move the user to. In order to find that GUID, you can use the `RoleCache.get_id_for_name()` and provide the name of the role.
 :::

### Kotlin

```java title="Change role of user"
user.changeRole(client, client.roleCache.getIdForName("\$guest")) // (1)
```

1. Use the `changeRole()` method to change the role of a user. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::tip[Use the `RoleCache` to find the right GUID]
The `changeRole()` method requires the GUID of the role you want to move the user to. In order to find that GUID, you can use the `RoleCache.getIdForName()` and provide the name of the role.
 :::

### Go

```go showLineNumbers title="Change role of user"
roleID, atlanErr := assets.GetRoleIDForRoleName("$guest")
ctx.UserClient.ChangeUserRole( // (1)
 "b060a754-4d16-4e13-b5a8-ba42f10aee39", // (2)
 roleID, // (3)
)
```

1. Use the `UserClient.ChangeUserRole()` method to change the role of a user.
2. Specify the GUID of the user whose role you want to change.
3. Specify the GUID of the role you want to change the user to.

 :::tip[Use the `RoleCache` to find the right GUID]
The `UserClient.ChangeUserRole()` method requires the GUID of the role you want to move the user to. In order to find that GUID, you can use the `assets.GetRoleIDForRoleName()` and provide the name of the role.
 :::

### Raw REST API

```json showLineNumbers title="POST /api/service/users/da213751-95de-4f96-8bee-a2c73e2ef8c8/update"
{
 "roleId": "0d1c39de-7323-4490-98d9-43240307eea7" // (1)
}
```

1. You must provide the unique ID (GUID) of the new role for the user.

 :::warning[You probably need to look this up first]
When using the raw API, you will need to lookup the role GUID yourself. You can `GET /api/service/roles`, and the GUID will be the `id` field in the response for each role.
 :::

### Deactivate user

:::warning[This can't be done programmatically]
You can only deactivate users as an Admin user (via the UI), API tokens don't have access to deactivate users.
:::

### Reactivate user

:::warning[This can't be done programmatically]
You can only reactivate users as an Admin user (via the UI), API tokens don't have access to reactivate users.
:::

---
