Last active
November 30, 2019 22:25
-
-
Save tyteen4a03/2f10851c27819c13b929d60df2643129 to your computer and use it in GitHub Desktop.
Freshdesk delete all contacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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