Scheduling Deletion of Inactive Users


This article details how to delete users that have been inactive for too long.

Applies To

  • User Management
  • User Deletion


Tenants have the Management API, which can be used to delete users programmatically. For example, a cron job could run a script to carry out the deletions. Please see Delete users by ID.

There are multiple SDKs that can be used to interact with the Management API to simplify the implementation, e.g., node-auth0 if NodeJS is the preferred language.

  • See the full list of supported backend SDKs here.

As for determining the users that need deletion, this would require searching for users that meet the criteria, collect the relevant user IDs and then finally trigger deletions of those user IDs.

  • Documentation for the user search endpoint can be found here.
  • Which user attributes are searchable can be found here.

For example, inactive users could be searched for by looking for old last_login dates. Here is an example of how to search for all users who last logged in before 2018 by using the below search query:

 last_login:[* TO 2017-12-31]

As a user search is limited to a total of 1000 results even with pagination, if it is anticipated that more than 1000 users will need deleting regularly, performing a bulk export of the users to analyze locally may be advised instead of using the user search endpoint. Please see the Related References section for more details.

It should also be pointed out that the Management API has rate limits. Therefore, it is best practice for any script using the API to take note of the returned rate limit response headers so that backoff and limited retry mechanisms can be carried out should the calls get close to or exceed the rate limits.

Related References