cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2671
Views
0
Helpful
5
Replies

Add Supervisor capability through UCCX API

SAN J
Level 2
Level 2

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.

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

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})

View solution in original post

5 Replies 5

dekwan
Cisco Employee
Cisco Employee

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

 

Anthony Holloway
Cisco Employee
Cisco Employee

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})

Thanks Anthony! Will try this out!

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.

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.

 

 

 

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: