• 0 Votes
    2 Posts
    429 Views
    F
    Finding Users with Email MFA Configured You can search for users with email MFA using the query string pattern in either the Admin UI search bar or via the Search API: twoFactor.methods.method:email This follows the same pattern used for searching users by any MFA method. Getting an Accurate Count Efficiently To get a count without retrieving all user records, use the Search API with accurateTotal enabled and a minimal numberOfResults: { "search": { "accurateTotal": true, "queryString": "twoFactor.methods.method:email", "numberOfResults": 1, "startRow": 0 } } The response will include a total field containing the exact count of matching users. Last-Used MFA Information Unfortunately, FusionAuth does not store a timestamp for when a user last used their MFA method. However, each MFA method object includes a lastUsed boolean field at users[x].twoFactor.methods[x].lastUsed that indicates which method was most recently used by that user. This is a boolean flag rather than a timestamp, so you can identify which method was used last but not when it was used.
  • 0 Votes
    2 Posts
    341 Views
    F
    You can use the User Search API with a must_not clause in the Elasticsearch query to exclude users registered to a specific application. Here's an example: curl -X POST https://sandbox.fusionauth.io/api/user/search \ -H 'Authorization: <your-api-key>' \ -H 'Content-Type: application/json' \ -d '{ "search": { "accurateTotal": true, "numberOfResults": 100, "startRow": 0, "query": "{\"bool\":{\"must_not\":[{\"nested\":{\"path\":\"registrations\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"registrations.applicationId\":\"<your-application-id>\"}}]}}}}]}}" } }' Key points: The must_not clause excludes users matching the nested query The nested query targets the registrations path since registrations are nested objects in the Elasticsearch mapping Inside the nested query, the must clause matches the specific applicationId Replace <your-application-id> with the UUID of your target application This returns users who either have no registrations at all, or have registrations to other applications but not the specified one You can paginate through results using startRow and numberOfResults if you have a large user base. Important: This approach requires the Elasticsearch search engine (not the database engine). You must use the search.query parameter with raw Elasticsearch JSON when querying against registrations, because it is defined as a nested datatype in the Elasticsearch mapping. The queryString parameter cannot be used for nested fields like registrations with expected results. Tip: You can use the Admin UI → Users → Advanced → Show Elasticsearch Query toggle to build and test queries interactively before using them in the API. Related Documentation User Search API - Elasticsearch Search Engine - Main API reference for searching users with Elasticsearch Searching Users With Elasticsearch or OpenSearch - Searching With query - Guide on using the query parameter for advanced searches User Search API - Additional Query Examples - Examples of various query patterns including nested queries Registrations - Core concepts documentation explaining the relationship between Users, Applications, and Registrations Field Mappings - Available fields for matching in Elasticsearch searches