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}')
Solution 1:
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
Solution 2:
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:
-
Get
-
List
-
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