HOW TO
The sharing level of ArcGIS Online and the Enterprise portal items can be updated to restrict or allow access according to the intended purpose of the items. To update the sharing level of items, refer to ArcGIS Online: Share items. However, manually sharing multiple items with an organization can be time-consuming. This article provides four simplified procedures using ArcGIS API for Python to update the sharing level of items in bulk for different scenarios.
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager
#For ArcGIS Online gis = GIS('https://arcgis.com', '<username>', '<password>') #For Portal for ArcGIS gis = GIS('https://<machine>.<domain>/<web adaptor name>/home', 'username', 'password', verify_cert=False) print ('Connected')
items_list = ['<itemID1>', '<itemID2>', '<itemID3>', '<itemID4>', '<itemID5>'] #To share within a group groupOrg = gis.groups.search('<group_name>')[0]
for item in items_list: ids = gis.content.get(item) #To make the item public ids.sharing.sharing_level = SharingLevel.EVERYONE #To share the item within organization ids.sharing.sharing_level = SharingLevel.ORG #To share the item within groups ids.sharing.groups.add(group=groupOrg) #To set only for owner ids.sharing.sharing_level = SharingLevel.PRIVATE
The code block below shows the full script to update the sharing level to everyone for ArcGIS Online.
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager gis = GIS('https://arcgis.com', 'user1', 'password1') print ('Connected') items_list = ['as65f468ae1s6a5f', 'sdv91sr1c651re6v', '5a1ec81rgsadf65v', 'sad1vr98ea165sd1f'] for item in items_list: ids = gis.content.get(item) ids.sharing.sharing_level = SharingLevel.EVERYONE
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager
#For ArcGIS Online gis = GIS('https://arcgis.com', '<username>', '<password>') #For Portal for ArcGIS gis = GIS('https://<machine>.<domain>/<web adaptor name>/home', 'username', 'password', verify_cert=False) print ('Connected')
items_list = gis.content.search('', item_type='Shapefile', max_items=-1) groupOrg = gis.groups.search('<group_name>')[0]
for item in items_list: #To make the item public item.sharing.sharing_level = SharingLevel.EVERYONE #To share the item within organization item.sharing.sharing_level = SharingLevel.ORG #To share the item within groups item.sharing.groups.add(group=groupOrg) #To set only for owner item.sharing.sharing_level = SharingLevel.PRIVATE
The code block below shows the full script to update the sharing level to a group for the Enterprise portal.
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager gis = GIS('https://test.esri.com/arcgis/home', 'username1', 'password1', verify_cert=False) print ('Connected') items_list = gis.content.search('', item_type='Shapefile', max_items=-1) groupOrg = gis.groups.search('TestUser')[0] for item in items_list: item.sharing.groups.add(group=groupOrg)
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager
#For ArcGIS Online gis = GIS('https://arcgis.com', '<username>', '<password>') #For Portal for ArcGIS gis = GIS('https://<machine>.<domain>/<web adaptor name>/home', 'username', 'password', verify_cert=False) print ('Connected')
items_list = gis.content.search(query = 'owner:<username>', max_items=-1) groupOrg = gis.groups.search('<group_name>')[0]
for item in items_list: #To make the item public item.sharing.sharing_level = SharingLevel.EVERYONE #To share the item within organization item.sharing.sharing_level = SharingLevel.ORG #To share the item within groups item.sharing.groups.add(group=groupOrg) #To set only for owner item.sharing.sharing_level = SharingLevel.PRIVATE
The code block below shows the full script to update the sharing level within the organization for ArcGIS Online.
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager gis = GIS('https://arcgis.com', 'user1', 'password1') print ('Connected') items_list = gis.content.search(query = 'owner:user1', max_items=-1) for item in items_list: item.sharing.sharing_level = SharingLevel.ORG
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager
#For ArcGIS Online gis = GIS('https://arcgis.com', '<username>', '<password>') #For Portal for ArcGIS gis = GIS('https://<machine>.<domain>/<web adaptor name>/home', 'username', 'password', verify_cert=False) print ('Connected')
user = gis.users.get('<username>') items_list = user.items(folder='<folder_name>', max_items=-1) groupOrg = gis.groups.search('<group_name>')[0]
for item in items_list: #To make the item public item.sharing.sharing_level = SharingLevel.EVERYONE #To share the item within organization item.sharing.sharing_level = SharingLevel.ORG #To share the item within groups item.sharing.groups.add(group=groupOrg) #To set only for owner item.sharing.sharing_level = SharingLevel.PRIVATE
The code block below shows the full script to update the sharing level to everyone for the Enterprise portal.
import arcgis from arcgis.gis import GIS from arcgis.gis import User from arcgis.gis._impl._content_manager import SharingLevel from arcgis.gis._impl._content_manager import SharingGroupManager gis = GIS('https://test.esri.com/arcgis/home', 'username1', 'password1', verify_cert=False) print ('Connected') user = gis.users.get('<username>') items_list = user.items(folder='<folder_name>', max_items=-1) for item in items_list: item.sharing.sharing_level = SharingLevel.EVERYONE
Article ID: 000035324
Get help from ArcGIS experts
Download the Esri Support App