How to Retrieve Last Login Dates for Multiple Users in FusionAuth via the Search API
-
We have ~8,000 usernames/emails and want to look up each user’s last login date. The UI seems to allow searching only one email at a time. Is there a way to upload a CSV of usernames and get all of their lastLoginInstant values?
-
FusionAuth doesn’t support uploading a CSV to retrieve last-login timestamps. However, you can do this efficiently with the Search for Users API and return lastLoginInstant for many users at once.
How to do it (batch via API)
-
Use the User Search endpoint
POST /api/user/search (set your X-FusionAuth-TenantId and Authorization headers). -
Send an Elasticsearch query using terms to match a batch of emails/usernames, and read lastLoginInstant from each returned user:
{ "search": { "query": "{\"terms\":{\"email\":[\"a@example.com\",\"b@example.com\",\"c@example.com\"]}}", "numberOfResults": 500, "startRow": 0 } }- Swap email for username if that’s what you have.
- If your list is large, chunk it (e.g., 200–500 logins per request) and paginate with startRow / numberOfResults.
- (Optional) Filter by last-login date with a range query on lastLoginInstant:
{ "search": { "query": "{\"range\":{\"lastLoginInstant\":{\"gte\":\"2025-10-01T00:00:00Z\"}}}" } }You can also query by epoch millis if you prefer.
- Map results
Each user object includes lastLoginInstant (epoch millis). Convert to your desired timezone/format in your script and write out a CSV.
Tips
- If you need all users in a tenant (not just your list), you can search with a wildcard or a match-all query and page through results, then filter locally.
- For ongoing metrics, consider subscribing to user.login.success webhooks and recording last logins as they happen.
Docs:
- Search for Users API (Elasticsearch): https://fusionauth.io/docs/apis/users#elasticsearch-search-engine
-
-
W wesley has marked this topic as solved