Skip to content

Instantly share code, notes, and snippets.

@poacosta
Last active July 31, 2023 20:55
Show Gist options
  • Save poacosta/c98c79dcb1c9c67247d8c507624f044a to your computer and use it in GitHub Desktop.
Save poacosta/c98c79dcb1c9c67247d8c507624f044a to your computer and use it in GitHub Desktop.
Delete Cometchat users and groups using Pyhon
# python -m pip install requests
import requests
url = "https://api-us.cometchat.io/v2"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"Accept": "application/json",
"appId": "---",
"apiKey": "---"
}
def items(selector, path) -> list:
return [i[selector] for i in requests.get(url + path + '?perPage=1000', headers=headers).json()['data']]
def delete_item(path, item, payload=None) -> None:
print('Deleting ' + item)
if payload is None:
requests.delete(url + path + '/' + item, headers=headers).json()
else:
requests.delete(url + path + '/' + item, json=payload, headers=headers).json()
def users() -> list:
return items('uid', '/users')
def delete_users() -> None:
usrs = users()
if len(usrs) == 0:
print('No users found')
else:
for uid in usrs:
delete_item('/users', uid, {"permanent": True})
print('Users deleted!')
def groups() -> list:
return items('guid', '/groups')
def delete_groups() -> None:
grps = groups()
if len(grps) == 0:
print('No groups found')
else:
for guid in grps:
delete_item('/groups', guid)
print('Groups deleted')
if __name__ == "__main__":
print(delete_users())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment