Home > Back-end >  Google Apps Script - AdminDirectory.Chromeosdevices returns empty recentUsers[0].email when unmanage
Google Apps Script - AdminDirectory.Chromeosdevices returns empty recentUsers[0].email when unmanage

Time:10-21

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
    
        }
      }
    }

CodePudding user response:

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.

  • Related