google-apps-scriptgoogle-admin-sdk

How to get department and manager's email through google admin sdk?


I am calling google admin directory api to get user through email and then storing the organizations return in org.

var user = AdminDirectory.Users.get(bmail);

org = user.organizations;

Output

[ { customType: '',
    title: 'PM',
    department: 'BIT',
    primary: true,
    description: 'Permanent' } ]

Any reference or help will be much appreciated.

Thank you


Solution

  • You already have the User object, so if you want to read the department property you only have to navigate its tree. See the example below:

    function myFunction() {
      var user = AdminDirectory.Users.get(bmail);
      org = user['organizations'][0]['department'];
    }
    

    Now to answer your second question you could use the relations field to keep track of the user's managers. Feel free to drop a comment if you need further clarifications.