Granting Access to a Group

Problem

You need to grant a group access to a content item.

Solution

from posit import connect

CONTENT_GUID = "c92da1ad-9c48-420f-8e2a-dcd2d58f9723"
GROUP_GUID = "286d77ab-cc4d-430d-848d-67c8179de942"
# Valid values are "viewer" and "owner" (collaborator)
ACCESS_TYPE = "viewer"

client = connect.Client()

# Add a group permission directly
group = client.groups.get(GROUP_GUID)
client.content.get(CONTENT_GUID).permissions.create(group, role=ACCESS_TYPE)

# Add a group permission manually
client.content.get(CONTENT_GUID).permissions.create(
    principal_guid=GROUP_GUID,
    principal_type="group",
    role=ACCESS_TYPE,
)

# Confirm new permissions
client.content.get(CONTENT_GUID).permissions.find()
library(connectapi)

CONTENT_GUID <- "c92da1ad-9c48-420f-8e2a-dcd2d58f9723"
GROUP_GUID <- "286d77ab-cc4d-430d-848d-67c8179de942"
# Valid values are "viewer" and "owner" (collaborator)
ACCESS_TYPE <- "viewer"

client <- connect()

# For the specified content item add the desired group
content <- content_item(client, CONTENT_GUID)
content_add_group(content, GROUP_GUID, role = ACCESS_TYPE)

# Confirm new permissions
get_content_permissions(content)