<?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 ArcGIS Online - Script to Delete User Content in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122735#M43205</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am an administrator for my organisations AGOL and we are hoping to automate the deletion of content.&lt;/P&gt;&lt;P&gt;We have an excel spreadsheet that lists the organisations users names, the name of their layers, file type, view count etc. We want to use this to filter out specific user content (i.e. low view count/ those that have left the organisation etc) and then automatically delete certain layers.&lt;/P&gt;&lt;P&gt;We are hoping to use a &lt;STRONG&gt;python script&lt;/STRONG&gt; to automate this deleting process. Has anyone done this previously?&lt;/P&gt;&lt;P&gt;Example workflow:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Connect to ArcGIS Online&lt;/P&gt;&lt;P&gt;2. For content type (identified in spreadsheet) and content name (identified in spreadsheet) delete&lt;/P&gt;&lt;P&gt;3. Loop to the next layer to delete.&lt;/P&gt;&lt;P&gt;As there are hundreds of these layers that will need to be deleted, any help on how to do this, where to start with the script would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 04 Dec 2021 14:15:54 GMT</pubDate>
    <dc:creator>mpinney</dc:creator>
    <dc:date>2021-12-04T14:15:54Z</dc:date>
    <item>
      <title>ArcGIS Online - Script to Delete User Content</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122735#M43205</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am an administrator for my organisations AGOL and we are hoping to automate the deletion of content.&lt;/P&gt;&lt;P&gt;We have an excel spreadsheet that lists the organisations users names, the name of their layers, file type, view count etc. We want to use this to filter out specific user content (i.e. low view count/ those that have left the organisation etc) and then automatically delete certain layers.&lt;/P&gt;&lt;P&gt;We are hoping to use a &lt;STRONG&gt;python script&lt;/STRONG&gt; to automate this deleting process. Has anyone done this previously?&lt;/P&gt;&lt;P&gt;Example workflow:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Connect to ArcGIS Online&lt;/P&gt;&lt;P&gt;2. For content type (identified in spreadsheet) and content name (identified in spreadsheet) delete&lt;/P&gt;&lt;P&gt;3. Loop to the next layer to delete.&lt;/P&gt;&lt;P&gt;As there are hundreds of these layers that will need to be deleted, any help on how to do this, where to start with the script would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 14:15:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122735#M43205</guid>
      <dc:creator>mpinney</dc:creator>
      <dc:date>2021-12-04T14:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Online - Script to Delete User Content</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122742#M43206</link>
      <description>&lt;P&gt;We have done something very similar to this. I'm assuming that your spreadsheet includes the itemID of these items? It's much easier if so, but this can be re-written if not. However you get there, you'll need a&amp;nbsp;&lt;STRONG&gt;list&amp;nbsp;&lt;/STRONG&gt;of ItemIDs. Here's a general example of the process:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS, Item

gis = GIS('your-url', 'user', 'pass')

# If you're using a spreadsheet, this might be where you read the sheet into a list, then only get the itemIDs.
item_id_list = [ ... ]

for i in item_id_list:
    item = Item(gis, i)
    
    # Check if you can delete the item first, then delete
    if item.can_delete:
        item.delete()
    else:
        print(f'{item.title}, id {item.id}, is delete protected.')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternately, if you're &lt;EM&gt;sure &lt;/EM&gt;that you want to delete these items regardless of potential delete protection, swap this in for the if / else at lines 12 - 15 above:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    if not item.can_delete:
        item.protect(enable=False)

    item.delete()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 16:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122742#M43206</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-04T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Online - Script to Delete User Content</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122937#M43225</link>
      <description>&lt;P&gt;To build on Josh's answer, if you don't already have the itemIDs listed, you can use &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;gis.content.search&lt;/FONT&gt;&lt;/STRONG&gt; to search for and access your folders and contents.&lt;/P&gt;&lt;P&gt;You can learn more about using the GIS module to search your contents &lt;A href="https://developers.arcgis.com/python/guide/accessing-and-creating-content/" target="_self"&gt;here.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

gis = GIS('your-url', 'user', 'pass')

#create an empty list that will be filled with items to be deleted
delete_list = []

# search your organization for content that has the desired name and type from your spreadsheet
search_results = gis.content.search('title: {}'.format(content_name), max_items=100)
for result in search_results:
    if result["title"] == content_name and result["type"] == content_type:
            delete_list.append(result)
for item in delete_list:
    # Check if you can delete the item first, then delete
    if item.can_delete:
        item.delete()
    else:
        print('{} is delete protected.'.format(item.title))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 15:02:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1122937#M43225</guid>
      <dc:creator>AmandaRing</dc:creator>
      <dc:date>2021-12-06T15:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Online - Script to Delete User Content</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1124090#M43261</link>
      <description>&lt;P&gt;Thanks both, this has been extremely useful. I’ll adapt this to my needs and update with final result for others to use.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 23:20:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-online-script-to-delete-user-content/m-p/1124090#M43261</guid>
      <dc:creator>mpinney</dc:creator>
      <dc:date>2021-12-08T23:20:32Z</dc:date>
    </item>
  </channel>
</rss>

