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']])