Generate a list of all workspace admins

Use the included sample code to generate a list of all workspace admins.

Written by simran.arora

Last published at: June 7th, 2023

Workspace administrators have full privileges to manage a workspace. This includes adding and removing users, as well as managing all of the data resources (jobs, libraries, notebooks, repos, etc.) in the workspace.

Delete

Info

You must be a workspace administrator to perform the steps detailed in this article. 

If you are a workspace admin, you can view other workspace admins in the workspace UI by using Admin Settings.

  1. Click your username in the top bar of the workspace.
  2. Click Admin Settings.
  3. Click Groups.
  4. Click the admins group.
  5. Review the list of workspace admins.

While the UI method works for most situations, in certain use cases you may need to get a list of workspace admins from within a notebook.

This article provides a sample code that you can use to list all of the workspace admins in the current workspace.

Instructions

We can use the following code to fetch the workspace admin users.

Delete

Info

To get your workspace URL, review Workspace instance names, URLs, and IDs (AWS | Azure | GCP).

Review the Generate a personal access token (AWS | Azure | GCP) documentation for details on how to create a personal access token for use with the REST APIs.


  1. Copy and paste the sample code into a notebook cell.
  2. Replace the <workspace-domain-name> and <personal-access-token> values with ones specific to your workspace.
  3. Run the cell to generate a list of all the admin users in your workspace.


%python

import requests
access_token= "<personal-access-token>"

headers={
 'Authorization': 'Bearer ' + access_token
}

response = requests.get(f"https://<workspace-domain-name>/api/2.0/preview/scim/v2/Groups", headers=headers) 

groups = response.json()
for admin in groups['Resources']:
    if admin.get('displayName')== 'admins':
        admin_group_id=admin.get('id')
        print(admin_group_id)

response = requests.get(f"https://<workspace-domain-name>/api/2.0/preview/scim/v2/Groups/{admin_group_id}", headers=headers) 
admin_group = response.json() 
members = admin_group.get('members', []) 
admin_users = [] 
for member in members:  
    admin_users.append(member.get('display'))

admin_users.sort()
print(admin_users)