HOW TO

Batch update sharing level of ArcGIS Online or the Enterprise portal items using Python version 2.4

Last Published: April 8, 2025

Summary

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.

Procedure

Update the sharing level of multiple items by specifying the item IDs

  1. Import the necessary modules.
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
  1. Connect to the account and specify the credentials.
#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')
  1. Specify the item IDs and, if applicable, the group name to be updated.
items_list = ['<itemID1>', '<itemID2>', '<itemID3>', '<itemID4>', '<itemID5>']

#To share within a group
groupOrg = gis.groups.search('<group_name>')[0]
  1. Iterate through all the items and update the sharing level using the Item.sharing and SharingManager properties.
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

Update the sharing level of items based on the file type

  1. Import the necessary modules.
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
  1. Connect to the account and specify the credentials.
#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')
  1. Search for the items based on the specified file type and specify the group name. Available file types are described in the following documentation: ArcGIS Developer: Items and item types. The following line demonstrates a shapefile used as the file type.
items_list = gis.content.search('', item_type='Shapefile', max_items=-1)
groupOrg = gis.groups.search('<group_name>')[0]
  1. Iterate through all the items and update the sharing level using the Item.sharing property.
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)

Update the sharing level of items owned by a username

  1. Import the necessary modules.
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
  1. Connect to the account and specify the credentials.
#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')
  1. Search for all items owned by a username and specify the group name, if applicable.
items_list = gis.content.search(query = 'owner:<username>', max_items=-1)
groupOrg = gis.groups.search('<group_name>')[0]
  1. Iterate through all the items and update the sharing level using the Item.sharing property.
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

Update the sharing level of all the items in a specific folder

  1. Import the necessary modules.
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
  1. Connect to the account and specify the credentials.
#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')
  1. Get the specific folder names and specify the group name, if applicable.
user = gis.users.get('<username>')
items_list = user.items(folder='<folder_name>', max_items=-1)
groupOrg = gis.groups.search('<group_name>')[0]
  1. Iterate through all the items and update the sharing level using the Item.sharing property.
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

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS API for Python
  • ArcGIS Enterprise

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options