Managing a Group’s Users

Problem

You want to view or adjust a group’s user membership.

Solution

from posit.connect import Client

client = Client()

group_guid = "GROUP_GUID_HERE"
user_guid = "USER_GUID_HERE"

# Get user and group objects
group = client.groups.get(group_guid)
user = client.users.get(user_guid)


# View users that belong to a group
group_users = group.members.find()

# Add user to a group
group.members.add(user)

# Remove a user from a group
group.members.delete(user)
library(connectapi)
library(dplyr)
client <- connect()

group_guid = "GROUP_GUID_HERE"
user_guid = "USER_GUID_HERE"


# View users that belong to a group
group_users <- get_group_members(client, group_guid)

# Add user to a group
client$PUT(paste0("groups/", group_guid, "/members"), body=list(user_guid=user_guid))

# Remove a user from a group
client$DELETE(paste0("groups/", group_guid, "/members/", user_guid))