You will learn: how to use the ArcGIS API for Python to programmatically change the sharing settings for your layers.

You can share layers, maps, and other items saved in your ArcGIS for Developers account with the public or choose to keep your content private. Until actively shared, items are not visible to others and do not appear in search results. Public items are accessible to everyone. Developers should keep in mind that an item's sharing settings will impact any apps consuming that item. For example, if you have an app that's using a web map, and the web map is later set to 'private', the app will not display that map. In this quick lab, you'll explore how to control the sharing settings with the ArcGIS API for Python. You can learn much more about sharing your layers and using groups by accessing ArcGIS Online documentation.

Before You Begin

The ArcGIS API for Python DevLabs use Jupyter Notebooks to execute Python code. If you are new to Python, please see the ArcGIS API for Python guide to Using the Jupyter notebook environment.

Complete the Create a new dataset DevLab. You will use the output feature layer to complete this DevLab.


Search for and update the sharing permissions of an item

  1. Go to the Esri Jupyter Notebook and click New > Python 3 to create a new notebook.

    In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.

  2. Add the following code in a cell to import the ArcGIS API for Python.

    from arcgis.gis import *
  3. Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace username and password with your own credentials.

    dev_gis = GIS("https://www.arcgis.com", "username", "password")
  4. Search for the Griffith Park Access layer created in the Create a new dataset DevLab.

    feature_layer_srch_results = dev_gis.content.search(query='title: "Griffith*" AND type: "Feature Service"')
  5. Retrieve the feature layer collection item from the list of results.

    feature_layer_coll_item = feature_layer_srch_results[0]
  6. Check the current sharing permissions of the layer.

    • Click the thumbnail link printed from the cell in step #4 to open the Item Details page
    • Check Shared with under Details on the right. It should say Organization
  7. Update the sharing permissions of the layer so that it's available to everyone.

  8. Check that the permissions have been updated.

    • Click the thumbnail link printed from the cell in step #4 to open the Item Details page
    • Check Shared with under Details on the right. It should now say Everyone (public)!

Congratulations, you're done!

Your notebook should now look something like this.


Create a new group and share the item with that group

In the ArcGIS API for Python, you can also programmatically create groups and share content to that group. Try this on your own by referencing this sample to create a group and the following sample to share content with the group.