HOW TO

Batch update sharing level of ArcGIS Online or Portal for ArcGIS items using ArcGIS API for Python

Last Published: December 28, 2023

Summary

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.

Procedure

Note:
The following script can be run on ArcGIS Notebook or as a stand-alone script.

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
  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 to be updated.
items_list = ['<itemID1>', '<itemID2>', '<itemID3>', '<itemID4>', '<itemID5>']
  1. Iterate through all the items and change the sharing level using the share() function.
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)

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
  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. Available file types are described in the following documentation, ArcGIS Developer: Items and item types. The following line demonstrates Shapefile as the file type selected.
items_list = gis.content.search('', item_type='Shapefile', max_items=-1)
  1. Iterate through all the items and change the sharing level using the share() function.
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)

Change 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
  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.
items_list = gis.content.search(query = 'owner:<username>', max_items=-1)
  1. Iterate through all the items and change the sharing level using the share() function.
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)

Change 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
  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.
user = gis.users.get('<username>')
items_list = user.items(folder='<folder_name>', max_items=-1)
  1. Iterate through all the items and change the sharing level using the share() function.
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

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS API for Python 1 x
  • ArcGIS Enterprise 10 9 x
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 2

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