Skip to content

Instantly share code, notes, and snippets.

@tyteen4a03
Last active November 30, 2019 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyteen4a03/2f10851c27819c13b929d60df2643129 to your computer and use it in GitHub Desktop.
Save tyteen4a03/2f10851c27819c13b929d60df2643129 to your computer and use it in GitHub Desktop.
Freshdesk delete all contacts
import requests
api_key = ('API-KEY-HERE', 'X')
domain = 'DOMAIN-HERE'
contact_ids = []
page = 1
while True:
print("Downloading page {} of deleted contacts".format(page))
results = requests.get("https://{}.freshdesk.com/api/v2/contacts?page={}&per_page=100&state=deleted".format(domain, page), auth=api_key).json()
if len(results) == 0:
break
for result in results:
contact_ids.append(result["id"])
page += 1
total = len(contact_ids)
print("Found {} contacts.".format(total))
for id in contact_ids:
print("Deleting contact ID {} of {}".format(id, total))
requests.delete("https://{}.freshdesk.com/api/v2/contacts/{}/hard_delete".format(domain, id), auth=api_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment