To remove a list of users from your platform, you can create a script that uses the Delete Users Bevy API.
Find here an example script you can use as a guide to do the user batch deletion.
Important notes before starting to work on this:
1- In order to prevent an overload of the system, the recommendation is to only do batches of 250 users maximum.
2- It is also important to consider the API Rate Limits before running any script:
- Authorized users: 10,000 requests per day (requests with an authentication token)
- Anonymous users: 5,000 requests per day
3- The Delete User API doesn't delete the user immediately, it sets the user for deletion, which means it will take 7 days for the user to be completely removed from the platform. During this period, you will be able to cancel the deletion.
4- We highly encourage testing the script with only one test user before uploading the entire list of users for deletion
Prerequisites:
Before you begin, ensure you have:
- API Access: Valid API Token with the necessary permissions.
- List of User IDs: create a list of the user_id's from the users you want to delete. In the example script, the list is stored in a csv file but this can be edited as required.
Example Script:
import csv import requests customer_url = "www.yourplatformurl.com"
auth_token = "xxxxxxxxxxxxx"
headers = {'Authorization' : "Token " + auth_token}with open ('your_users_to_delete.csv', newline='') as csvfile:
#Replace 'your_users_to_delete.csv' with your file name #Create a file where to store the information of the deleted users with open ('users_set_to_delete.csv', 'w', newline='') as results: fieldnames = ['email', 'user_id'] writer = csv.DictWriter(results, fieldnames=fieldnames) writer.writeheader() reader =csv.DictReader(csvfile, delimiter = ',') next (reader, None) for row in reader: try:
#Makes the DELETE API call to set the user for deletion r = requests.delete(customer_url + row['user_id'], headers=headers) if(r.status_code >= 400): print("Error for user " + row['user_id']) else: writer.writerow({ 'email': row['email'], 'user_id': row['user_id'] })
This script will set the list of users for deletion and creates a file with the list of users that are set for deletion, for tracking purposes.
Comments