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_HERE"
group_guid = "USER_GUID_HERE"
user_guid
# Get user and group objects
= client.groups.get(group_guid)
group = client.users.get(user_guid)
user
# View users that belong to a group
= group.members.find()
group_users
# Add user to a group
group.members.add(user)
# Remove a user from a group
group.members.delete(user)
library(connectapi)
library(dplyr)
<- connect()
client
= "GROUP_GUID_HERE"
group_guid = "USER_GUID_HERE"
user_guid
# View users that belong to a group
<- get_group_members(client, group_guid)
group_users
# Add user to a group
$PUT(paste0("groups/", group_guid, "/members"), body=list(user_guid=user_guid))
client
# Remove a user from a group
$DELETE(paste0("groups/", group_guid, "/members/", user_guid)) client