Question

Add user groups to a Space with read or edit via API

  • 25 January 2019
  • 3 replies
  • 158 views

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.


3 replies

Userlevel 7
Badge +1

Check out this fabulous post by the one and only @jesse.carah:



Manage Space Access with the API

@Girish_G I found that when the space is inheriting, you cannot add other content_metadata_access to it. I needed to remove inheritance, then add the 1 group I wanted to grant access.



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)

@Girish_G yep, @JoeR is totally right. What Joe is doing from that update_content_metadata call is the equivalent of toggling these options in the UI on a Space’s settings:


02%20PM



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