HOW TO

Retrieve Portal for ArcGIS or ArcGIS Online item properties and resource details using ArcGIS API for Python

Last Published: March 25, 2024

Summary

Item properties and resources of a feature describe and reference the content in ArcGIS Pro, ArcGIS Online, and ArcGIS Enterprise. The properties are used in search to identify the specific items requested by the user, for example, a search using the item ID. When large amounts of data are involved, Esri recommends using Python scripts to ease the process. Identifying item properties can be done using the resources.list() function in ArcGIS API for Python. However, an empty result may be returned when the function is run on hosted items. This is expected behavior as the property details of a hosted item resides in the item's JSON.

This article describes how to use ArcGIS API for Python to access the item properties in JSON. The script provided can be run on a stand-alone .py file or in ArcGIS Notebook.

Procedure

  1. Import the necessary module.
from arcgis.gis import GIS
import json
  1. Connect to the account and specify the credentials.
    • For ArcGIS Online:
gis = GIS('https://arcgis.com', '<username>', '<password>')
gis = GIS(r'https://essorg.maps.arcgis.com', client_id='<client_id>', client_secret='<client_secret>', verify_cert=False)
  • For Portal for ArcGIS:
gis = GIS(r'https://<machine>.<domain>/<web adaptor name>/home', 'username', 'password', verify_cert=False)
  1. Specify the item ID. This can be done individually by using a single parameter, or multiple by using an array parameter.
  • For a single item.
item_id = "<item_id>"
  • For multiple items, more item IDs can be added by modifying the script as shown in the example.
items = ["<item_id_1>", "<item_id_2>", "<item_id_3>", "<item_id_4>"]
  1. Get the item resource details.
    • For full details of a single item:
item = gis.content.get(item_id)
print(json.dumps(dict(item), indent=4))
  • For full details of multiple items:
for item_id in items:
    item = gis.content.get(item_id)
    print(json.dumps(dict(item), indent=4))
  • For specific details of a single item, modify the print statement to return the desired detail.
item = gis.content.get(item_id)
print(item["type"])
print(item["owner"])
print(item["title"])
print(item["url"])
  • For specific details of multiple items, modify the print statement to return the desired detail.
for item_id in items:
    item = gis.content.get(item_id)
    print(item["type"])
    print(item["typeKeywords"])
    print(item["title"])
    print(item["url"])

The following shows the full script to print all the item details for multiple items.

from arcgis.gis import GIS
import json

gis = GIS("https://essorg.maps.arcgis.com", client_id="bcqwu37r8uboeqsample", client_secret="c2safh3q48hrinf487cbriecbsample", verify_cert=False)

items = ["cf9983q4fciuewn4b3rev983qncubwei6", "1097h13498hcunc2405bffn549"]

for item_id in items:
    item = gis.content.get(item_id)
    print(json.dumps(dict(item), indent=4))

Article ID: 000032244

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