Due to some item sharing apis being deprecated, I'm updating my code to use the group sharing manager APIs. But I must be doing something totally wrong because when I check the item sharing states via the item -> overview -> share button, the api calls to add and remove the item from the group don't seem to have any effect. I created a notebook (attached) with each step so I can do the sequences of share, test, unshare, test etc in any order. The code is listed below. When I run this from start to finish, the item appears not to be shared with the group. Any ideas on what I'm doing wrong?
from arcgis.gis import GIS
gis = GIS("home")
# Initialize item and group variables
ITEM_ID = '747f78beae544888aa58ebf3dd17b258'
print (f"Item: {gis.content.get(ITEM_ID).title}")
GROUP_ID = 'dfedf7528fac409b8d96b0ffb940edd2'
print (f"Group: {gis.groups.get(GROUP_ID).title}")
# Test if the item is shared with the group
print (GROUP_ID in [g.id for g in gis.content.get(ITEM_ID).sharing.shared_with['groups']])
# Unshare the item with group
gis.content.get(ITEM_ID).sharing.groups.remove(gis.groups.get(GROUP_ID))
# Share the item with the group
gis.content.get(ITEM_ID).sharing.groups.add(gis.groups.get(GROUP_ID))
# Print all items shared with the group
print([(i.id,i.title) for i in gis.groups.get(GROUP_ID).content(max_items=9999)])
# Print all groups that the item is shared with
print ([(g.id, g.title) for g in gis.content.get(ITEM_ID).sharing.shared_with['groups']])
Solved! Go to Solution.
Hi @DonMorrison1,
Your code works perfectly fine for me as of API Version 2.4.0.
How many groups is the item already shared with? There seemed to be an initial bug when it was shared with more than 5 as per details here.
At least we can rule out that issue if your item is not shared with many groups.
All the best,
Glen
Hi @DonMorrison1,
Your code works perfectly fine for me as of API Version 2.4.0.
How many groups is the item already shared with? There seemed to be an initial bug when it was shared with more than 5 as per details here.
At least we can rule out that issue if your item is not shared with many groups.
All the best,
Glen
I've always suspected it was related to the number of shares on the item but could never figure out the threshhold. The item I'm testing with is shared with more than 5 groups. I'm running on API version 2.4.0 and it appears there will be a fix in 2.4.1. I'll do some more testing to verify I'm running into the same problem.
This is exactly my problem - thanks for finding that issue. I wasn't even aware of that git site's existence