I need to delete contacts - a LOT of contacts - 429s galore

24 views
Skip to first unread message

Matthew Weiner

unread,
Jun 26, 2026, 11:21:56 AM (2 days ago) Jun 26
to GAM for Google Workspace
So the Powers that Be at my district decided they don't like looking at stale contacts in their personal address books so I was directed to "find a way" of clearing out contacts in the system from employees that no longer exist.

I banged out a nifty PowerShell script thanks to AI and after several hours of running came up with a CSV file of... 126,000 contacts that need purging (and no that's not a mistake).  Hello 429 errors!  I've split the CSV, I've reduced parallelism to one process, still if I run this command:

gam config num_threads 1 csv inactive_contacts_chunk13.csv gam user ~User delete othercontacts ~resourceName

I'll smack into 429 errors in a minute, maybe two of running it.  Any way to fix this, I need to get rid of 126,000 contacts and Google's API is not liking it at all!

Thanks!

Matthew Weiner

unread,
Jun 26, 2026, 3:58:39 PM (2 days ago) Jun 26
to GAM for Google Workspace
Huge, huge thanks to Ross, we figured it out!

csvkmd to the rescue!

If you run this command you will avoid all but the occasional passing backoff that doesn't hurt anything:
gam csvkmd users (csv-file-name) keyfield (user csv field) datafield (contact id csv field) delete othercontacts csvdata (contact id csv field)

I did generate my CSV with only the otherContacts data to avoid false lookups from the People entries, you could do the same or tweak the csvkmd commands to only return those rows.  So mine, using the standard gam contacts csv output looks like this:
gam csvkmd inactive_contacts_filtered.csv keyfield User datafield resourceName delete othercontacts csvdata resourceName

Hope this helps the next person that needs to delete 100,000 contacts!
Reply all
Reply to author
Forward
0 new messages