I would like to get a list of all users for 3 AD groups on our Tableau server site using the TSC package. Based on some resources out there, I have the below using Python.
The first snippet of code returns all users on our site and exports the list to an Excel. The second snippet is my attempt to apply a filter that returns just the users in the 3 AD groups, but it returns 0 users.
Our site uses AD groups to provision access. I need to validate whether the members of these 3 groups have access to the data source the dashboard uses. The plan is to get the list of users from Tableau server and merge the group list with the list of users with access to the data source to return an output that would flag instances where I get a left only in _merge.
Any input would be much appreciated.
Returns all users on site.
import tableauserverclient as TSC
import pandas as pd
tableau_auth = TSC.PersonalAccessTokenAuth('Y14_Dashboard_Update','access-token-xyz',site_id = 'site-name')
server = TSC.Server('https://tableau-site/',use_server_version=True)
with server.auth.sign_in(tableau_auth):
request_options = TSC.RequestOptions(pagesize=1000)
all_users, pagination_item = server.users.get(request_options)
print("nThere are {} user on site: ".format(pagination_item.total_available))
all_users_on_site = pd.DataFrame({'Users': [user.name for user in all_users]})
all_users_on_site.to_excel(r"C:\UsersTABLEAU_User_MEDocumentsProjectsTableau_Users.xlsx", index = False)
Modified to filter on 3 groups; returns 0 users.
import tableauserverclient as TSC
import pandas as pd
tableau_auth = TSC.PersonalAccessTokenAuth('Y14_Dashboard_Update','access-token-xyz',site_id = 'site-name')
server = TSC.Server('https://tableau-server-site/',use_server_version=True)
with server.auth.sign_in(tableau_auth):
request_options = TSC.RequestOptions(pagesize=1000)
request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.In,
["AD-Group1","AD-Group2", "AD-Group3"],)
)
matching_groups, pagination_item = server.users.get(request_options)
print("nThere are {} user on site: ".format(pagination_item.total_available))
all_users_on_site = pd.DataFrame({'Users': [user.name for user in matching_groups]})
all_users_on_site.to_excel(r"C:\UsersTABLEAU_User_MEDocumentsProjectsTableau_Users.xlsx", index = False)
2
Here’s the final edit to get all users. The comment from MUFF was helpful. Thanks!
import tableauserverclient as TSC
import pandas as pd
tableau_auth = TSC.PersonalAccessTokenAuth('Y14_Dashboard_Update','access-token-xyz',site_id = 'site-name')
server = TSC.Server('https://tableau-site/',use_server_version=True)
with server.auth.sign_in(tableau_auth):
request_options = TSC.RequestOptions(pagesize=1000)
request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.In,
["AD-Group1","AD-Group2", "AD-Group3"],)
)
all_groups, pagination_item = server.groups.get(request_options)
all_users, pagination_item = server.users.get(request_options)
mygroup2 = all_groups[1]
pagination_item = server.groups.populate_users(mygroup2)
#list of all users in AD groups with IDs
for user in mygroup2.users:
all_users_on_site = pd.DataFrame({'Users': [user.name for user in mygroup2.users],
'id': [user.id for user in mygroup2.users]
})
2
does it have to use tableauserverclient and in python ?
Otherwise, you can query the Tableau repository ( after enabling access to it ) to it, for similar results.
1