Getting groups for a user using Python SDK

python

#1

Hi,

I’m trying to get the groups that a user is a member of using the python SDK. I need to call this API - https://developer.okta.com/docs/api/resources/users.html#get-member-groups. How can I do this using the python SDK? I wasn’t able to find anything here - https://developer.okta.com/docs/sdk/core/python_api_sdk/index.html. Thanks in advance for your help.


#2

You can use the the method Add User To Group By ID:

from okta import UserGroupsClient

groups_client = UserGroupsClient("https://{org}.oktapreview.com", "API_KEY")
group = groups_client.get_groups(query="UniqueGroupName")[0]

# Add user to group by ID
groups_client.add_user_to_group_by_id(group.id, user.id)