# Gerry O'Rourke # 30 September 2024 # Version 1.0 ################################################################################################################################################# # 1. Configure a template Finesse config against an individual team using Finesse Admin GUI and confirm all OK. # # Document the Team ID which has been configured with this template (team ID is a column on the Finesse Admin teams page) # # # # 2. Download the template using the API - https://<finesse-server/finesse/api/Team/<Team-ID>/LayoutConfig # # example: https://finesse-a.example.com/finesse/api/Team/5259/LayoutConfig # # This will ensure that the xml file is in the correct format. # # Note - you can use a browser to do this. You will be prompted for the Finesse admin's username & password. # # and once the layout xml is displayed on the screen - just right click and select "Save As" # # # # 3. Upload the template to a webserver - in the below example I upload to the IIS Server where I also run the python script, # # hence I use http://localhost. # # # # 4. Configure the team_ids array and the layoutName Variable (the filename)- as per below example. # # NOTE - If layoutName is NOT set - the default layout is assumed! # # # # 5. Configure the Finesse URL, admin, password and the webserver url where the layoutName templates are located. # # # # The script will downloads the XML template file and uploads it to the relevant teams (with a delay of 0.5 seconds between each team). # # Repeat the steps for each Template and group of teams you need to update # ################################################################################################################################################# import requests # used for http requests from requests.auth import HTTPBasicAuth import sys # used for sys.exit import urllib3 # import os #check / creating folders urllib3.disable_warnings() #Surpress cert warnings import xml.etree.ElementTree as ET from time import sleep # Set Finesse FQDN, username & password below finesseHost = 'ucce-finesse-a.example.com' finesseUsername = 'admin' finessePassword = 'Pa$$w0rd' # Location where you place the layout templates you want to upload to Finesse. template_base_url = 'http://localhost/layouts/' # Set team_ids & set 'layoutName'. If no layoutName set - it will set those teams to use the default layout. # i.e. comment out 'layoutName' is you want to set the default layout for those teams. #Team1 #team_ids = [5075] #layoutName = 'Layout-simple-template1.xml' #Team2 #team_ids = [5333] #layoutName = 'Layout-simple-template2.xml' #BothTeams (set as many team ids you need) team_ids = [5075,5333] layoutName = 'Layout-Home-MyStats-MyHist-LCM-Chat-PeopleFinder.xml' # all gadgets example ################################################################################################################################################## def get_layout(): url = template_base_url + '/' + layoutName response = requests.get(url) responseStatusCode = (response.status_code) responseText = response.text if (responseStatusCode == 200): #print(responseText) xml = responseText for id in team_ids: layout_update(id,xml) sleep(500/1000) else: print('StatusCode: ' + str(responseStatusCode)) print('failed to retrieve Layout File: ' + layoutName) def layout_update(id,xml): url = 'https://' + finesseHost + '/finesse/api/Team/' + str(id) + '/LayoutConfig' basic = HTTPBasicAuth(finesseUsername, finessePassword) response = requests.put(url, verify=False, auth=basic, headers={"Content-Type":"application/xml"}, data = xml) responseStatusCode = (response.status_code) responseText = response.text if (responseStatusCode == 200): print('Team Id: ' + str(id) + ' updated.') else: print ('statusCode: ' + str(responseStatusCode)) print('Layout Update failed with team id ' + str(id)) print (xml) exit(1) def are_you_sure(): confirm = input('\nAre you sure you want to continue (Y/N)?') if confirm == 'Y' or confirm =='y': print("...") else: print("No Confirmation Inputted. Exiting...\n") exit() try: team_ids except NameError: print("'team_ids' has been not defined.\nSet 'team_ids' correctly. Exiting...") exit(1) else: print("'team_ids' is set to: " + str(team_ids)) try: layoutName except NameError: print("'layoutName' has been NOT been defined, hence the **default** layout will be set for these teams.") are_you_sure() print('Starting Layout Update...') xml = '<TeamLayoutConfig><useDefault>true</useDefault></TeamLayoutConfig>' for id in team_ids: layout_update(id,xml) sleep(500/1000) else: print("'layoutName' is set to: " + layoutName + '\n') print('Starting Layout Update...') are_you_sure() get_layout()