FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    How to Retrieve Last Login Dates for Multiple Users in FusionAuth via the Search API

    Scheduled Pinned Locked Moved Solved
    Frequently Asked Questions (FAQ)
    api
    1
    2
    11
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wesley
      last edited by

      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?

      W 1 Reply Last reply Reply Quote 0
      • W
        wesley @wesley
        last edited by

        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)

        1. Use the User Search endpoint
          POST /api/user/search (set your X-FusionAuth-TenantId and Authorization headers).

        2. 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.
        1. (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.

        1. 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
        1 Reply Last reply Reply Quote 0
        • W wesley has marked this topic as solved
        • First post
          Last post