pythongoogle-cloud-platformgoogle-apigoogle-groups

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

  • 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 your-group-name@domain.com

    which will return something similar to:

    createTime: '2019-01-01T00:00:00.000000Z'
    displayName: YourGroupName
    groupKey:
      id: your-group-name@domain.com
    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