Search code examples
pythongoogle-apigoogle-directory-api

Google Directory API groups


I am trying to use Google's admin directory API (with Google's python library).

I am able to list the users on the directory just fine, using some code like this:

results = client.users().list(customer='my_customer').execute()

However, those results do not include which groups the users are a member of. Instead, it appears that once I have the list of users, I then have to make a call to get a list of groups:

results = client.groups().list(customer='my_customer').execute()

And then go through each group and call the "members" api to see which users are in a group:

results = client.members().list(groupKey='[group key]').execute()

Which means that I have to make a new request for every group.

It seems to be horribly inefficient. There has to be a better way than this, and I'm just missing it. What is it?


Solution

  • There is no better way than the one you described (yet?): Iterate over groups and get member list of each one.

    I agree that is not the answer you want to read, but it is also the way we do maintenance over group members.