<?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: Using a csv list of usernames to delete AGOL users in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768789#M602</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following works for me to create the list of users that need to be deleted from a csv of their usernames in the first column.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;

with open(csvPath) as f_input:
&amp;nbsp;&amp;nbsp;&amp;nbsp;csv_input = csv.reader(f_input, delimiter=",")
&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in csv_input:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;users = gis.users.search("username:{}".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (len(users)&amp;gt;0): # only append if there are search results
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userDelete.append(users[0])&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:53:59 GMT</pubDate>
    <dc:creator>KimberlySaballett</dc:creator>
    <dc:date>2021-12-12T16:53:59Z</dc:date>
    <item>
      <title>Using a csv list of usernames to delete AGOL users</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768788#M601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello - I've been working on writing some scripts to help clean up our AGOL membership.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This community has been great - I've been using Richard Stokes question (and notebook) to help get started:&amp;nbsp;&lt;A _jive_internal="true" href="https://community.esri.com/message/713234-batch-deleting-users-based-on-a-role"&gt;https://community.esri.com/message/713234-batch-deleting-users-based-on-a-role&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm running into some problems deleting a list of around 140 users based on a CSV file (our GIS group came up with a list of criteria and created and exported this list of usernames from AdminTools). It's a single column CSV with just usernames (the column heading is "Username").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I understand it, I need get each user account, release their licenses, delete their content, and then delete the member.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I seem to be doing something very basic incorrectly in my initial loop through the list of usernames to get each user account from AGOL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;EM&gt;#Import modules&lt;BR /&gt;&lt;/EM&gt;from arcgis.gis import GIS&lt;BR /&gt;import csv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;#Declare GIS&lt;BR /&gt;gis = GIS("https://claremont.maps.arcgis.com", "adminName", "psswrd")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;#Make list of users to delete&lt;/EM&gt;&lt;BR /&gt;userDelete = []&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with open(r"4_22_2019InactiveUsers2.csv") as f_input:&lt;BR /&gt; csv_input = csv.DictReader(f_input)&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for row in csv_input:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;users = row[gis.users.search("username:Username")]&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;userDelete.append(users)&lt;BR /&gt; &lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; border: 0px; font-size: 14px; padding: 1px 0px;"&gt;&lt;SPAN class="" style="color: #b22b31; font-weight: bold;"&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;SPAN class="" style="color: #b22b31; font-weight: bold;"&gt;TypeError&lt;/SPAN&gt;                                 Traceback (most recent call last)&lt;SPAN class="" style="color: #007427; font-weight: bold;"&gt;&amp;lt;ipython-input-28-d415de218329&amp;gt;&lt;/SPAN&gt; in &lt;SPAN class="" style="color: #60c6c8;"&gt;&amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #00a250;"&gt;      2&lt;/SPAN&gt;     csv_input &lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;=&lt;/SPAN&gt; csv&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;.&lt;/SPAN&gt;DictReader&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;(&lt;/SPAN&gt;f_input&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #00a250;"&gt;      3&lt;/SPAN&gt;     &lt;SPAN class="" style="color: #007427; font-weight: bold;"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="" style="color: #007427; font-weight: bold;"&gt;in&lt;/SPAN&gt; csv_input&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #007427; font-weight: bold;"&gt;----&amp;gt; 4&lt;/SPAN&gt;&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;         &lt;/SPAN&gt;users &lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;[&lt;/SPAN&gt;gis&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;.&lt;/SPAN&gt;users&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;.&lt;/SPAN&gt;search&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #0065ca; font-weight: bold;"&gt;"username:Username"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #00a250;"&gt;      5&lt;/SPAN&gt;         userDelete&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;(&lt;/SPAN&gt;users&lt;SPAN class="" style="color: #b27d12; font-weight: bold;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #00a250;"&gt;      6&lt;/SPAN&gt;  &lt;SPAN class="" style="color: #b22b31; font-weight: bold;"&gt;TypeError&lt;/SPAN&gt;: unhashable type: 'list'&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions appreciated - I'm new &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp; Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2019 19:37:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768788#M601</guid>
      <dc:creator>JeanineFinn</dc:creator>
      <dc:date>2019-05-20T19:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using a csv list of usernames to delete AGOL users</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768789#M602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following works for me to create the list of users that need to be deleted from a csv of their usernames in the first column.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;

with open(csvPath) as f_input:
&amp;nbsp;&amp;nbsp;&amp;nbsp;csv_input = csv.reader(f_input, delimiter=",")
&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in csv_input:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;users = gis.users.search("username:{}".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (len(users)&amp;gt;0): # only append if there are search results
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userDelete.append(users[0])&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:53:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768789#M602</guid>
      <dc:creator>KimberlySaballett</dc:creator>
      <dc:date>2021-12-12T16:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a csv list of usernames to delete AGOL users</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768790#M603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks - this worked very well!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2019 18:45:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-a-csv-list-of-usernames-to-delete-agol-users/m-p/768790#M603</guid>
      <dc:creator>JeanineFinn</dc:creator>
      <dc:date>2019-05-24T18:45:08Z</dc:date>
    </item>
  </channel>
</rss>

