So far I have the list of users, but i don't know how to export them. Can anyone help me here?
import tableauserverclient as TSC
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
server = TSC.Server('https://SERVER_URL', use_server_version=True)
with server.auth.sign_in(tableau_auth):
# get specified the group
req_option = TSC.RequestOptions()
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.Equals,
'ABC'))
all_groups, pagination_item = server.groups.get(req_option)
mygroup = all_groups[0]
print(mygroup.name,mygroup.id)
#print(mygroup[0])
# get user information from the group
pagination_item = server.groups.populate_users(mygroup)
# print the names of the users
for user in mygroup.users:
if user.last_login is None:
print(user.name,user.site_role, user.last_login)
@Bhavana Khairnar
Hi, in this case you can use:
import tableauserverclient as TSC
import csv
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
server = TSC.Server('https://SERVER_URL', use_server_version=True)
#Create the csv file and open it in write mode
f = open('usuarios.csv', 'w', encoding='UTF8', newline='')
#delimiter with semicolon if needed change to comma
writer = csv.writer(f, delimiter=";")
#write the header
header = ['User','Site Role','Last Login']
writer.writerow(header)
#tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
#server = TSC.Server('https://SERVER_URL', use_server_version=True)
with server.auth.sign_in(tableau_auth):
# get specified the group
req_option = TSC.RequestOptions()
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.Equals,
'Modux'))
all_groups, pagination_item = server.groups.get(req_option)
mygroup = all_groups[0]
print(mygroup.name,mygroup.id)
#print(mygroup[0])
# get user information from the group
pagination_item = server.groups.populate_users(mygroup)
# print the names of the users
for user in mygroup.users:
# if user.last_login is None:
row=[user.name,user.site_role,user.last_login]
print(user.name, user.site_role, user.last_login)
#write the row
writer.writerow(row)
#Close file connection
f.close()
#Don't forget to sign out
server.auth.sign_out()
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego
Tableau Ambassador