<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Item ID only returning title in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552583#M10800</link>
    <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;A FeatureLayerCollection is a Feature Service at heart. Let's begin with an Item object. An Item object represents any content item in your AGOL/Portal. Once you have an Item object, you can get what Item type it is representing.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access ArcGIS Online
agol = GIS("home")

## get Feature Service Item (Feature Layer Collection)
fs_item = agol.content.get("ITEM_ID")

print(fs_item)
&amp;lt;Item title:"Buffer_Testing" type:Feature Layer Collection owner:FinalDraftMapping&amp;gt;

print(fs_item.type)
Feature Service

## get WebMap Item
wm_item = agol.content.get("ITEM_ID")

print(wm_item)
&amp;lt;Item title:"Mean_Center_WebMap" type:Web Map owner:FinalDraftMapping&amp;gt;

print(wm_item.type)
Web Map

## get Shapefile Item
shp_item = agol.content.get("ITEM_ID")

print(shp_item)
&amp;lt;Item title:"NPWS_BIO_DesignatedAreaBoundaries" type:Shapefile owner:FinalDraftMapping&amp;gt;

print(shp_item.type)
Shapefile

## get CSV Item
csv_item = agol.content.get("ITEM_ID")

print(csv_item)
&amp;lt;Item title:"ARCGISAFP03_DHLGH_HER_NIAH_CSV" type:CSV owner:FinalDraftMapping&amp;gt;

print(csv_item.type)
CSV&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, depending on the Item type, you can convert/cast to its proper object. For examples, you can create a FeatureLayerCollection object from a Feature Service, or a WebMap (Map at version 2.4.0) from a Web Map item.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
from arcgis.mapping import WebMap
## from arcgis.map import Map # this is for version 2.4.0+

## access ArcGIS Online
agol = GIS("home")

## get Feature Service Item (Feature Layer Collection)
fs_item = agol.content.get("ITEM_ID")

## create FLC object
flc = FeatureLayerCollection.fromitem(fs_item) # will fail if you supply any other item type
print(type(flc))
&amp;lt;class 'arcgis.features.layer.FeatureLayerCollection'&amp;gt;

## get WebMap Item
wm_item = agol.content.get("ITEM_ID")
wm = WebMap(wm_item)
print(type(wm))
&amp;lt;class 'arcgis.mapping._types.WebMap'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code below will fail because &lt;EM&gt;&lt;STRONG&gt;item&lt;/STRONG&gt; &lt;/EM&gt;is a Service Definition and not a Feature Service. You need your item to be of type Feature Service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## item needs to be a Feature Service not a Service Definition
manager = arcgis.features.FeatureLayerCollection.fromitem(item).manager&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the most part, an Item object represents what you see in that Items page and setting in AGOL. Converting/casting to its proper object (FLC, WebMap etc) open up interacting in more depth. For example, FLC will allow updating symbology and popups for example. For a WebMap you can add and remove layers. A FLC object has its own set of methods and properties, and similar with a WebMap object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only use dict(item) when you want to access the properties of an Item object. It takes the item object and casts it to a dictionary so you can see the JSON definition for the item.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Oct 2024 09:29:24 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2024-10-26T09:29:24Z</dc:date>
    <item>
      <title>Item ID only returning title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552057#M10794</link>
      <description>&lt;P&gt;I am trying to connect to ArcGIS Online and retrieve information on an item using an item ID. My code is as follows:&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; arcgis &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; arcgis.gis &lt;/SPAN&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; GIS&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;gis = GIS(url='&lt;A href="https://unc.maps.arcgis.com" target="_blank" rel="noopener"&gt;https://unc.maps.arcgis.com&lt;/A&gt;', username='my_username', password='mypassword')&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;itemid &lt;/SPAN&gt;&lt;SPAN class=""&gt;= '9d4c5e75fa5b4bcabbb6161bafe10f57'&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;item = gis.content.get(itemid)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;The code runs with out error, but it only returns the title:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;print(item)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;lt;Item title:"Vision_Zero_Safety" type:Shapefile owner:my_username'&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;It I attempt to get other information such as:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;item&lt;/SPAN&gt;&lt;SPAN class=""&gt;.resources.list()&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;it returns an empty list:&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;[]&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;Could this be due to permission issues? I've tried to retrieve information on other items I have but it always just returns the title. I've doubled checked the item id's and they are correct.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 19:54:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552057#M10794</guid>
      <dc:creator>jmpmcmanus</dc:creator>
      <dc:date>2024-10-24T19:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Item ID only returning title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552267#M10796</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/560433"&gt;@jmpmcmanus&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By printing item you are printing the item object and what you are being returned is correct.&lt;/P&gt;&lt;P&gt;What do you want to get from the item object? An item object has a dict base.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import json
...

## probably wont print pretty
print(dict(item))

## print out the json for the item in a more readable fashion
print(json.dumps(item, indent= 4)

## if a feature service item
print(item.layers) # a list of FeatureLayer objects
print(item.tables) # a list of Table objects&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each item object has different options based on the item type. For example, a WebMap item return information when using item.get_data() where a Feature Layer Collection item (Feature Service) will return an empty list.&lt;/P&gt;&lt;P&gt;You can access some class properties, similar to .layers and .tables. Just check out the reference docs &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#item" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;You are accessing a Shapefile item, so you need to figure out if printing dict(item) returns the information you desire or what is it exactly you want to get from the item?&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 11:05:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552267#M10796</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-10-25T11:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Item ID only returning title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552502#M10799</link>
      <description>&lt;P&gt;Hi Glen&lt;/P&gt;&lt;P&gt;That is very helpful.&lt;/P&gt;&lt;P&gt;I'm taking the course&amp;nbsp;&lt;A href="https://www.esri.com/training/catalog/6410bdd94d750615175b1de1/updating-realtime-data-using-arcgis-python-libraries/" target="_self"&gt;Updating Realtime Data Using ArcGIS Python Libraries&lt;/A&gt;&amp;nbsp;. In the section Update and online feature service STEP 2 h the following code returns and error:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;item = gis.content.get(itemid)
sd_file_name = os.path.basename(original_sd_file)
if sd_file_name != item.related_items("Service2Data")[0].name:
    raise Exception('Erroneous itemid or original sd file'.format(itemid))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The error returned is:&lt;/P&gt;&lt;P&gt;*** IndexError: list index out of range&lt;/P&gt;&lt;P&gt;I changed the if statement using a dict(item) as you described and it work:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if sd_file_name != dict(item)['name']:
  raise Exception('Erroneous itemid or original sd file'.format(itemid))&lt;/LI-CODE&gt;&lt;P&gt;However, further down the code item is used again:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;manager = arcgis.features.FeatureLayerCollection.fromitem(item).manager &lt;/LI-CODE&gt;&lt;P&gt;This time the error is:&lt;/P&gt;&lt;P&gt;*** TypeError: item must be a type of service, not Service Definition&lt;/P&gt;&lt;P&gt;I looked at the&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayerCollection.fromitem" target="_self"&gt;Documentation for FeatureLayerCollection fromitem&lt;/A&gt;&amp;nbsp;but did not find anything that made sense to me. I'm not sure what items in item it is trying to use. Possibly it uses them all. The documentation you provide on item says it should be a dictionary, but using dict(item) did not work&lt;/P&gt;&lt;P&gt;Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 18:57:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552502#M10799</guid>
      <dc:creator>jmpmcmanus</dc:creator>
      <dc:date>2024-10-25T18:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Item ID only returning title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552583#M10800</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;A FeatureLayerCollection is a Feature Service at heart. Let's begin with an Item object. An Item object represents any content item in your AGOL/Portal. Once you have an Item object, you can get what Item type it is representing.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access ArcGIS Online
agol = GIS("home")

## get Feature Service Item (Feature Layer Collection)
fs_item = agol.content.get("ITEM_ID")

print(fs_item)
&amp;lt;Item title:"Buffer_Testing" type:Feature Layer Collection owner:FinalDraftMapping&amp;gt;

print(fs_item.type)
Feature Service

## get WebMap Item
wm_item = agol.content.get("ITEM_ID")

print(wm_item)
&amp;lt;Item title:"Mean_Center_WebMap" type:Web Map owner:FinalDraftMapping&amp;gt;

print(wm_item.type)
Web Map

## get Shapefile Item
shp_item = agol.content.get("ITEM_ID")

print(shp_item)
&amp;lt;Item title:"NPWS_BIO_DesignatedAreaBoundaries" type:Shapefile owner:FinalDraftMapping&amp;gt;

print(shp_item.type)
Shapefile

## get CSV Item
csv_item = agol.content.get("ITEM_ID")

print(csv_item)
&amp;lt;Item title:"ARCGISAFP03_DHLGH_HER_NIAH_CSV" type:CSV owner:FinalDraftMapping&amp;gt;

print(csv_item.type)
CSV&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, depending on the Item type, you can convert/cast to its proper object. For examples, you can create a FeatureLayerCollection object from a Feature Service, or a WebMap (Map at version 2.4.0) from a Web Map item.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
from arcgis.mapping import WebMap
## from arcgis.map import Map # this is for version 2.4.0+

## access ArcGIS Online
agol = GIS("home")

## get Feature Service Item (Feature Layer Collection)
fs_item = agol.content.get("ITEM_ID")

## create FLC object
flc = FeatureLayerCollection.fromitem(fs_item) # will fail if you supply any other item type
print(type(flc))
&amp;lt;class 'arcgis.features.layer.FeatureLayerCollection'&amp;gt;

## get WebMap Item
wm_item = agol.content.get("ITEM_ID")
wm = WebMap(wm_item)
print(type(wm))
&amp;lt;class 'arcgis.mapping._types.WebMap'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code below will fail because &lt;EM&gt;&lt;STRONG&gt;item&lt;/STRONG&gt; &lt;/EM&gt;is a Service Definition and not a Feature Service. You need your item to be of type Feature Service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## item needs to be a Feature Service not a Service Definition
manager = arcgis.features.FeatureLayerCollection.fromitem(item).manager&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the most part, an Item object represents what you see in that Items page and setting in AGOL. Converting/casting to its proper object (FLC, WebMap etc) open up interacting in more depth. For example, FLC will allow updating symbology and popups for example. For a WebMap you can add and remove layers. A FLC object has its own set of methods and properties, and similar with a WebMap object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only use dict(item) when you want to access the properties of an Item object. It takes the item object and casts it to a dictionary so you can see the JSON definition for the item.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2024 09:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552583#M10800</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-10-26T09:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Item ID only returning title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552966#M10803</link>
      <description>&lt;P&gt;That worked. Thanks Glen!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 19:32:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/item-id-only-returning-title/m-p/1552966#M10803</guid>
      <dc:creator>jmpmcmanus</dc:creator>
      <dc:date>2024-10-28T19:32:37Z</dc:date>
    </item>
  </channel>
</rss>

