<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[I want to delete all the users created before a certain time]]></title><description><![CDATA[<p dir="auto">How can I do so using the api?</p>
]]></description><link>https://fusionauth.io/community/forum/topic/307/i-want-to-delete-all-the-users-created-before-a-certain-time</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Mar 2026 03:38:24 GMT</lastBuildDate><atom:link href="https://fusionauth.io/community/forum/topic/307.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Aug 2020 22:37:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to I want to delete all the users created before a certain time on Mon, 17 Aug 2020 22:43:11 GMT]]></title><description><![CDATA[<p dir="auto">First, make sure you are using the elasticsearch search engine. You can't run this kind of query on the database search engine.</p>
<p dir="auto">Then, you want to use a range query: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html" rel="nofollow ugc">https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html</a></p>
<p dir="auto">You want to build your query string. This is a query string that gives you all the users between the two <code>insertInstant</code>s on the user object (inclusive):</p>
<pre><code> {
 	"range": {
 		"insertInstant": {
 			"gte": 1592231314000,
 			"lte": 1592231315735
 		}
 	}
 }
</code></pre>
<p dir="auto">Omit the <code>gte</code> key if you only want users before a certain time.</p>
<p dir="auto">Next is to turn it into an API call against the user search API, which means escaping the query's json and turning it into a JSON object suitable for FusionAuth to parse:</p>
<pre><code>curl -XPOST -H 'Content-type: application/json' -H "Authorization: $API_KEY" 'https://HOSTNAME/api/user/search?' -d ' { "search" : { "query" :  "{\"range\" : { \"insertInstant\" : { \"gte\" : 1592231314000, \"lte\" : 1592231315735}} }"}}'
</code></pre>
<p dir="auto">Finally, after testing to make sure you're getting the users back you want, you can run the bulk delete API, as documented here: <a href="https://fusionauth.io/docs/v1/tech/apis/users#bulk-delete-users" rel="nofollow ugc">https://fusionauth.io/docs/v1/tech/apis/users#bulk-delete-users</a></p>
<p dir="auto">Tested with Elasticsearch 7.</p>
]]></description><link>https://fusionauth.io/community/forum/post/877</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/877</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Mon, 17 Aug 2020 22:43:11 GMT</pubDate></item></channel></rss>