HOW TO
The sharing level of ArcGIS Online or Portal for ArcGIS items can be changed to restrict or allow access according to the intended purpose of the items. The sharing level can be changed by following the steps provided in the following documentation, ArcGIS Online: Share items. However, sharing multiple items with an organization can be time-consuming if performed manually. This article provides a simplified procedure using ArcGIS API for Python to change the sharing level in bulks for different scenarios.
Note: The following script can be run on ArcGIS Notebook or as a stand-alone script.
import arcgis from arcgis.gis import GIS from arcgis.gis import User
#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>']
for item in items_list:
ids = gis.content.get(item)
#To make the item public ids.share(everyone = True, allow_members_to_edit = True) #To share the item within organization ids.share(org = True, allow_members_to_edit = True) #To share the item within groups ids.share(groups = '<group id>', allow_members_to_edit = True) #To set only for owner ids.share(groups = '', org=False, everyone=False, allow_members_to_edit = False)
The code block below shows the full script to change the sharing level to everyone for ArcGIS Online.
import arcgis from arcgis.gis import GIS from arcgis.gis import User 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.share(everyone = True, allow_members_to_edit = True)
import arcgis from arcgis.gis import GIS from arcgis.gis import User
#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)
for item in items_list: #To make the item public item.share(everyone = True, allow_members_to_edit = True) #To share the item within organization item.share(org = True, allow_members_to_edit = True) #To share the item within groups item.share(groups = '<group id>', allow_members_to_edit = True) #To set only for owner item.share(groups = '', org=False, everyone=False, allow_members_to_edit = False)
The code block below shows the full script to change the sharing level to a group for Portal for ArcGIS.
import arcgis from arcgis.gis import GIS from arcgis.gis import User 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) for item in items_list: item.share(groups = 'as6f18e1f6as51fd', allow_members_to_edit = True)
import arcgis from arcgis.gis import GIS from arcgis.gis import User
#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)
for item in items_list: #To make the item public item.share(everyone = True, allow_members_to_edit = True) #To share the item within organization item.share(org = True, allow_members_to_edit = True) #To share the item within groups item.share(groups = '<group id>', allow_members_to_edit = True) #To set only for owner item.share(groups = '', org=False, everyone=False, allow_members_to_edit = False)
The code block below shows the full script to change the sharing level within the organization for ArcGIS Online.
import arcgis from arcgis.gis import GIS from arcgis.gis import User 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.share(org = True, allow_members_to_edit = True)
import arcgis from arcgis.gis import GIS from arcgis.gis import User
#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)
for item in items_list: #To make the item public item.share(everyone = True, allow_members_to_edit = True) #To share the item within organization item.share(org = True, allow_members_to_edit = True) #To share the item within groups item.share(groups = '<group id>', allow_members_to_edit = True) #To set only for owner item.share(groups = '', org=False, everyone=False, allow_members_to_edit = False)
The code block below shows the full script to change the sharing level to everyone for Portal for ArcGIS.
import arcgis from arcgis.gis import GIS from arcgis.gis import User 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.share(everyone = True, allow_members_to_edit = True)
Article ID: 000031704
Get help from ArcGIS experts
Download the Esri Support App