Reputation: 43
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.
Upvotes: 1
Views: 3999
Reputation: 403
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);
Upvotes: 0
Reputation: 5424
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.
Upvotes: 9
Reputation: 13528
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.
Upvotes: 0