0

the AdminDirectory.Chromeosdevices API will return and empty value in recentUsers[0].email, if the user accessing the Chromebook is not a member of the managed organisation. Why is that?

See the following code:

    function testDevices() {
      var optionalArgs = {   
        maxResults: 200,
        orderBy: 'serialNumber'
      };
      var arrValues = [];
    
      // get devices statuts
      var response = (AdminDirectory.Chromeosdevices.list("my_customer", optionalArgs));
      var devices = response.chromeosdevices;
      if (devices && devices.length > 0) {
        Logger.log('Testing:');
        var row;
        for (i = 0; i < devices.length; i++) {
          var device = devices[i];
          var ip;
          // some devices return undefined IP
          if (device.lastKnownNetwork){
             ip = device.lastKnownNetwork[0].ipAddress;
          }else{
            ip = "";
          }
          Logger.log(`Device ${device.serialNumber} IP:${ip} - ${device.recentUsers[0].email}`); 
// Undefined recentUsers[0].email when unmanaged
    
        }
      }
    }
Riccardo
  • 2,054
  • 6
  • 33
  • 51

1 Answers1

1

As the documentation for RecentUsers specifies

  1. For type there are two types of the user:

USER_TYPE_MANAGED: The user is managed by the domain.

USER_TYPE_UNMANAGED: The user is not managed by the domain.

  1. For email:

The user's email address. This is only present if the user type is USER_TYPE_MANAGED.


In other words:

Domain-external users are of a type for which the user's email address is not present.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Thanks for helping :-) Who knows why Google opted for this model? If you are the legit owner of the device, which is managed, why not track any user? – Riccardo Oct 20 '21 at 14:11