import requests import sys # Sisense API base URL and authentication token host_url = "" base_url = f"{host_url}/api/v1" api_token = "" # Construct the URL for getting the list of dashboards url = f"{base_url}/dashboards/admin?dashboardType=owner&ownerInfo=false&asObject=false&fields=shares%2Coid%2Ctitle" # Set up the headers with the authentication token headers = { "Authorization": f"Bearer {api_token}", "Content-Type": "application/json", } # Function to get the list of dashboards for a particular user def get_user_dashboards(user_name): # Make the GET request dash = requests.get(url, headers=headers) # Check if the request was successful (status code 200) if dash.status_code == 200: dashboards = dash.json() else: print(f"Error: {dash.status_code} - {dash.text}") # Construct the URL for getting the list of users url2 = f"{base_url}/users?fields=_id%2CuserName%2Cgroups" # Make the GET request userscontent = requests.get(url2, headers=headers) # Check if the request was successful (status code 200) if userscontent.status_code == 200: users = userscontent.json() else: print(f"Error: {userscontent.status_code} - {userscontent.text}") # Find dashboards where user_name is a substring of shares.userName for user in users: if user_name in user["userName"]: user_id = user["_id"] user_groups = user.get("groups", []) user_dashboards = [ dashboard["title"] for dashboard in dashboards if any( user_id == share["shareId"] or share["shareId"] in user_groups for share in dashboard["shares"] ) ] # Output the result print(f"{user['userName']}'s Dashboards: {', '.join(user_dashboards)}") # Check if a command-line argument is provided if len(sys.argv) > 1: # Get the userName from the command line user_name_argument = sys.argv[1] # Call the function with the provided userName get_user_dashboards(user_name_argument) else: print("Please provide a userName substring as a command-line argument.")