Search code examples
box-apiboxapiv2

User's last login time?


I'd like to know when a given user last logged in. It seems that the User object doesn't include this information (creation and modification only). Should I look to leverage the Events API (seems inefficient) or am I missing something obvious?


Solution

  • Yes, look to the Events API for this. Specifically, you'll want to use the Enterprise Events API and query for events of the type LOGIN. This requires an access token with administrative privileges.

    curl https://api.box.com/2.0/events?stream_type=admin_logs&event_type=LOGIN \
    -H "Authorization: Bearer ACCESS_TOKEN"
    

    Note that:

    • The returned events are paged, so you may need to adjust the page size or execute multiple queries to find the event(s) you're looking for.
    • You can use the created_after and created_before query parameters to limit the returned events to a specific time period.
    • You can also look for FAILED_LOGIN events: event_type=LOGIN,FAILED_LOGIN