Lets assume we have a Space for which we need to add a couple of groups with different access types(view or edit).
Is there a way we can add these user groups using an API. I was not able to figure out using Content Management APIs.
Add user groups to a Space with read or edit via API
I would up doing something like:
# content_metadata id for my space is 1567
sdk.update_content_metadata(1567, {inherits: false})
cma = Hash(
content_metadata_id: 1567,
permission_type: "edit",
group_id: 15
)
sdk.create_content_metadata_access(cma)
Here’s another example of Ruby code that creates a nested space and gives a group edit access to it. I added some comments that should give some context into what you might want to do for your case:
...
# Space body
space_body = {
name: "Nested Space Test",
parent_id: 1
}
# Create Space and save relevant variables
new_space = sdk.create_space(space_body).to_attrs
new_space_cm_id = new_space[:content_metadata_id].to_s
new_space_id = new_space[:id]
# Print to console to check out
puts "\nNew Space Info:\n#{new_space}"
puts "\nNew Space ID: #{new_space_id}"
puts "\nNew Space CM ID: #{new_space_cm_id}\n"
# Turn off inheritance
sdk.update_content_metadata(new_space_cm_id, {inherits: false})
# Body for content access to add
content_body = {
content_metadata_id: new_space_cm_id,
permission_type: "edit",
group_id: 4
}
# Add content access
content_access = sdk.create_content_metadata_access(content_body).to_attrs
# Did it work?
puts "\nCreate Content Metadata Access Response:\n#{content_access}"
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.