Not Able to Get Portal Item Properties and Resource Using ArcGIS API for Python

351
1
Jump to solution
01-12-2024 05:58 PM
BHK
by
New Contributor III

Having an array of Portal Items like

p_items = ['9912a5ec3325460ab88010cfefddwr21',
           '9251s4de1s1460ab88010cfe64seyus', 
           'ssdf2a5ec3325541dgs10cfefd21syx'
]

 

I need to retrieve two properties of   Type of Items weather is (Feature Layer (hosted, view) ,or  Feature Layer (hosted), or Map Image Layer )

BHK_0-1705110696010.png

 

and also, the URL referring into the source (ArcGIS Server Feature Service)

 

BHK_1-1705110713054.png

 

I already tried this

 

p_items = ['9912a5ec3325460ab88010cfefddwr21',
           '9251s4de1s1460ab88010cfe64seyus', 
           'ssdf2a5ec3325541dgs10cfefd21syx'
]
for item in p_items:
    item_id = item
    p_item = gis.content.get(item_id)
    item_resource = p_item.resources.list()

 

but the `item_resource` is always empty! Can you please let me know what I am missing here and how I can achieve this?

 

 

 

1 Solution

Accepted Solutions
Clubdebambos
Occasional Contributor III

Hi @BHK 

You get this information from the JSON of the item object. Run the code below to print out the properties of an item.

 

 

from arcgis.gis import GIS
import json

agol = GIS("home")

item_id = "ITEM_ID"
item = agol.content.get(item_id)
print(json.dumps(dict(item), indent=4))

 

 

In the type and typeKeywords you will find the information your are looking for. It is not always obvious but your Feature Service and View will be of type Feature Service, the view will have a typeKeyword of View Service in the list. The Map Image Layer will have a type of Map Service. Use the below to print out the type and typeKeywords properties for an item and the url.

 

 

from arcgis.gis import GIS
import json

agol = GIS("home")

p_items = ["ITEM_ID1", "ITEM_ID2", "ITEM_ID3"]

for item_id in p_items:
    item = agol.content.get(item_id)
    print(item["type"])
    print(item["typeKeywords"])
    print(item["url"])

 

 

This link is useful for type and typeKeyword combinations: https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm 

~ learn.finaldraftmapping.com

View solution in original post

1 Reply
Clubdebambos
Occasional Contributor III

Hi @BHK 

You get this information from the JSON of the item object. Run the code below to print out the properties of an item.

 

 

from arcgis.gis import GIS
import json

agol = GIS("home")

item_id = "ITEM_ID"
item = agol.content.get(item_id)
print(json.dumps(dict(item), indent=4))

 

 

In the type and typeKeywords you will find the information your are looking for. It is not always obvious but your Feature Service and View will be of type Feature Service, the view will have a typeKeyword of View Service in the list. The Map Image Layer will have a type of Map Service. Use the below to print out the type and typeKeywords properties for an item and the url.

 

 

from arcgis.gis import GIS
import json

agol = GIS("home")

p_items = ["ITEM_ID1", "ITEM_ID2", "ITEM_ID3"]

for item_id in p_items:
    item = agol.content.get(item_id)
    print(item["type"])
    print(item["typeKeywords"])
    print(item["url"])

 

 

This link is useful for type and typeKeyword combinations: https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm 

~ learn.finaldraftmapping.com