How to manually delete a lot of users?
-
I've been running some tests of a migration script for copying users from a legacy system to FusionAuth. As a result, I have a test installation containing a lot of junk users with mistakes and missing groups etc, which I would like to delete. However, I don't want to just do a fresh reinstall, as I have the necessary API keys, groups, applications etc already set up for my test environment.
Maybe I'm completely short-sighted (well, I am, that's true) but I can't find a way to simply select multiple users from the admin panel and delete them from the system. I can see the controls for adding or removing them from groups, but when it comes to simply deleting them, I'm not seeing it. My setup doesn't use ElasticSearch, so I can't do it via the query API.
Is it really impossible to just check a bunch of users and delete them?
-
Hiya!
If all the junk users are isolated in a tenant, you can delete the tenant to remove them all.
If they are in the default tenant, or a tenant which you don't want to delete, the easiest way is to use the API:
curl -XDELETE -H"Authorization: apikeyhere" 'https://auth.example.com/api/user/bulk?hardDelete=true&userId=id1&userId=id2&userId=id3'
(not tested, but should work)
You could use the search API +jq to build the list of userIds. If you have a lot, you can also use the request body, see the docs for details.
-
At this point, you may also consider creating a KickStart script that loads the basic configuration with mentioned API keys, groups etc. into a fresh FA installation. You've mentioned that you are working on a test installation, so during the further tests you will probably fill it again with new test data entities. If so, it will most likely be easier to recreate the FA with basic configuration via KickStart, rather than to pick unnecessary entities and delete them one by one. Such script also stands as a good documentation on what configurations has been made to meet your environment requirements.
This post may be a bit off the topic, but from my experience such approach quickly pays off, so you can at once solve your issue and boost up your testing environment ergonomics.