Tristan Bilot
Tristan Bilot

Reputation: 479

Fetch Google Group members

I'm trying to fetch all the members of a Google Group using the discovery API. So I used the code given in the doc but I get the following error:

'Error(2033): Group resource name has the correct format of `groups/{group_id}`, but it contains an invalid `{groupd_id}`

I used as group_id the email of the Google Group or the plain text name but the error persists. What is the correct syntax for that group id?

Code:

group_id = 'my_google_group@my_organization.com'
request = service.groups().memberships().searchTransitiveMemberships(parent=f'groups/{group_id}')

Upvotes: 2

Views: 2681

Answers (3)

dnnshssm
dnnshssm

Reputation: 1305

Just wanted to comment on Dave's good answer, but I don't have enough rep..

If you do want to get the group name programmatically, in case you're handling several groups for example, have a look at those docs.

There, groupName gives you the name in the required format (groups/...), group_id is the email of the group in that case.

Side note: the docs do not seem up to date, I had to remove + "&groupKey.namespace=identitysources/" + identity_source_id from the second line for it to work.

Upvotes: 0

Dave McLean
Dave McLean

Reputation: 156

You can get get the group_id of a group that you know the e-mail of using the gcloud console:

$ gcloud identity groups describe [email protected]

which will return something similar to:

createTime: '2019-01-01T00:00:00.000000Z'
displayName: YourGroupName
groupKey:
  id: [email protected]
labels:
  cloudidentity.googleapis.com/groups.discussion_forum: ''
name: groups/8673hkdnjaod98f
parent: customers/Cjas8duwn
updateTime: '2021-01-01T00:00:00.000000Z'

the relevant part for you is:

name: groups/8673hkdnjaod98f

so in this example the group_id is: 8673hkdnjaod98f

Upvotes: 3

To retrieve the information from the Cloud Identity’s GCP groups, you have 3 more options or “methods” that are specified in GCP’s official documentation:

  1. Get

  2. List

  3. Directory API: Groups

In the worst scenario that none of them work, it could be because you don't have an IAM role as "Owner" for GCP, even if you are signing in with your super admin user for G Suite. You can use the following official GCP’s documentation about it here GCP: Understanding roles

Upvotes: 2

Related Questions