04-16-2020 09:58 AM
I've been working with the UCCX APIs lately. Trying to see now if it's possible to use the CCX API to assign resources with supervisor capabilities. I've tried changing the "type" under resources from "1" to "2" but CCX rejected that request. Working with Cisco Sandbox UCCX v12.5. TIA.
Solved! Go to Solution.
05-06-2020 11:16 AM - edited 05-07-2020 01:23 PM
I don't think it's available in the API either, but I do know how to "hack" a solution together using Python + Requests to mimic a web interaction.
Check out this proof of concept to get you started. I provide no support on this solution, please do your due diligence when running random code off the internet on your production systems. ;)
#!/usr/bin/env python import requests from urllib.parse import parse_qs from bs4 import BeautifulSoup requests.packages.urllib3.disable_warnings() # Connection Info hostname = "uccx.domain.com" username = "administrator" password = "p@assw0rd" target_user = "aholloway" target_role = "Supervisor" # Static URLs url_base = f"https://{hostname}" url_appadmin = f"{url_base}/appadmin" url_main = f"{url_appadmin}/main" url_login = f"{url_appadmin}/j_security_check" url_get_token = f"{url_appadmin}/JavaScriptServlet" url_user_search = f"{url_appadmin}/LDAPSetup?request_type=ldapsetup.waitpage.usermaintenance&wizard=&isonload=false" url_user_modify = f"{url_appadmin}/LDAPSetup" # Establish Initial Connection and Get JSESSION Cookie, etc. connection = requests.Session() resp = connection.get(url_main, verify = False) # Get CSRF Token for Session resp = connection.post(url_get_token, verify = False, headers={'Referer':url_main,'FETCH-CSRF-TOKEN':'1'}) token = resp.content[10:] # Login to UCCX form_data = dict(j_username = username, j_password = password) resp = connection.post(url_login, verify = False, data = form_data) # Perform User Search to Get Current Capabilities form_data = { "request_type":"ldapsetup.next.usermaintenance", "chkLoginUser":"false", "search_criteria":target_user, "CSRFTOKEN":token } resp = connection.post(url_user_search, verify = False, data = form_data, headers={'Referer':url_main,'CSRFTOKEN':token}) soup = BeautifulSoup(resp.content, features="html.parser") caps = parse_qs(soup.find_all('td', string=target_user)[0].find('a')['href'])['cap'][0] # Modify the User (assumes at least Agent role exists, and you are adding one or more new roles) form_data = { "request_type":"ldapsetup.userupdate", "users":f"{caps},{target_role}", "request_type_axl":"ldapsetup.next.usermaintenance", "selected_user":target_user, "setup":"null", "deploymentType":"1", "userView":"false", "chkLoginUser":"false", "CSRFTOKEN":token } resp = connection.post(url_user_modify, verify = False, data = form_data, headers={'Referer':url_main})
04-20-2020 11:28 AM
Hi,
I am not an expert on the UCCX APIs and use them based off of the documentation. I am assuming you already have the documentation for the UCCX APIs, but here it is for folks stumbling upon this post while searching on the forum: https://developer.cisco.com/docs/contact-center-express/#!configuration-api-dev-guide
In the appadmin GUI, you usually have to change the user's role via the User Management page. I do not see a user management API available. Since you said you already tried to use the "Modify Resource" API with no success, I don't see any other API that can be used to change the user's capability via an API.
Thanx,
Denise
05-06-2020 11:16 AM - edited 05-07-2020 01:23 PM
I don't think it's available in the API either, but I do know how to "hack" a solution together using Python + Requests to mimic a web interaction.
Check out this proof of concept to get you started. I provide no support on this solution, please do your due diligence when running random code off the internet on your production systems. ;)
#!/usr/bin/env python import requests from urllib.parse import parse_qs from bs4 import BeautifulSoup requests.packages.urllib3.disable_warnings() # Connection Info hostname = "uccx.domain.com" username = "administrator" password = "p@assw0rd" target_user = "aholloway" target_role = "Supervisor" # Static URLs url_base = f"https://{hostname}" url_appadmin = f"{url_base}/appadmin" url_main = f"{url_appadmin}/main" url_login = f"{url_appadmin}/j_security_check" url_get_token = f"{url_appadmin}/JavaScriptServlet" url_user_search = f"{url_appadmin}/LDAPSetup?request_type=ldapsetup.waitpage.usermaintenance&wizard=&isonload=false" url_user_modify = f"{url_appadmin}/LDAPSetup" # Establish Initial Connection and Get JSESSION Cookie, etc. connection = requests.Session() resp = connection.get(url_main, verify = False) # Get CSRF Token for Session resp = connection.post(url_get_token, verify = False, headers={'Referer':url_main,'FETCH-CSRF-TOKEN':'1'}) token = resp.content[10:] # Login to UCCX form_data = dict(j_username = username, j_password = password) resp = connection.post(url_login, verify = False, data = form_data) # Perform User Search to Get Current Capabilities form_data = { "request_type":"ldapsetup.next.usermaintenance", "chkLoginUser":"false", "search_criteria":target_user, "CSRFTOKEN":token } resp = connection.post(url_user_search, verify = False, data = form_data, headers={'Referer':url_main,'CSRFTOKEN':token}) soup = BeautifulSoup(resp.content, features="html.parser") caps = parse_qs(soup.find_all('td', string=target_user)[0].find('a')['href'])['cap'][0] # Modify the User (assumes at least Agent role exists, and you are adding one or more new roles) form_data = { "request_type":"ldapsetup.userupdate", "users":f"{caps},{target_role}", "request_type_axl":"ldapsetup.next.usermaintenance", "selected_user":target_user, "setup":"null", "deploymentType":"1", "userView":"false", "chkLoginUser":"false", "CSRFTOKEN":token } resp = connection.post(url_user_modify, verify = False, data = form_data, headers={'Referer':url_main})
05-07-2020 01:01 PM
Thanks Anthony! Will try this out!
05-07-2020 01:25 PM - edited 05-07-2020 01:26 PM
I just fixed a typo on the line with "search_criteria":target_user, as there was an erroneous double quote between the r and the comma. Just double check you don't have that in your copy/paste. Or just copy and paste again. Cheers! Let me know how it goes. I tested it out on a 12.5 system.
03-04-2021 09:01 AM
Has anyone else managed to get this to work?
I get a 403 error at step 2.
I rewrote it to use MSXML2.serverXMLHTTP or WinHttp.WinHttpRequest.5.1 requests and get varying results, but never get the CSRF token back.
Tried against UCCX 12.5 and 11.6.2.
Really trying to automate this step so that the rest of my bulk loader scripts (via REST API) can work together.
Appreciate any feedback.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide