Is it possible to list users in a specific orgunit with the google admin sdk directory api?

StackOverflow https://stackoverflow.com/questions/20654177

  •  19-09-2022
  •  | 
  •  

Frage

Im using the Directory API in the Google admin SDK to manage users in Google domains. I'm looking for a way to list users in a specific orgunit in the domain but I don't find any examples on how to achieve this. According to the documentation https://developers.google.com/admin-sdk/directory/v1/reference/users/list the only valid query attributes are email, familyName and givenName. The workaround im using today is to get all users in the domain and then filter the response.

War es hilfreich?

Lösung 2

Your findings are correct, there's no way to retrieve only users in a given OU. You can retrieve just email and OrgUnit using the fields parameter and then filter locally. Using fields should reduce traffic and improve efficiency somewhat.

Andere Tipps

This is possible using the query parameter.

Example:

/admin/directory/v1/users?domain=domain.com&query=orgUnitPath=/Sales

or, url encoded:

/admin/directory/v1/users?domain=example.com&query=orgUnitPath%3D%2FSales

Will return all users in the /Sales orgunit.

Full docs here.

I used the 'query' parameter as explained in https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list and it works.

var optionalArgs = {
        customer: 'my_customer',
        orderBy: 'email',
        query: "orgUnitPath='/A1 - Current Members'"
      };
    
   var response = AdminDirectory.Users.list(optionalArgs);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top