google-apps-scriptgoogle-admin-sdkgoogle-workspacegoogle-reporting-api

Programmatically fetch user's last login date to G Suite


On a user's page on the G Suite admin console, an admin can see the last login of a user. For example, one user I can see has a "last login" date of two years ago.

I'm trying to pull this date programatically. However, the Reports API that provides information on login events only goes back 180 days. How is Google getting this login date, and can it be fetched via API?


Solution

  • I somehow missed this before, but you can get the last login date/time with the User Usage Report (rather than the Login Activity report).

    API docs are here and the App Script example I'm using is here. I realized that if GAM was pulling the information there had to be an API for it.