<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UCCX REST API for User Roles in Contact Center</title>
    <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080725#M10981</link>
    <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check out this proof of concept to get you started.&amp;nbsp; I provide no support on this solution, please do your due diligence when running random code off the internet on your production systems.&amp;nbsp; ;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;#!/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&amp;amp;wizard=&amp;amp;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})&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 May 2020 18:20:41 GMT</pubDate>
    <dc:creator>Anthony Holloway</dc:creator>
    <dc:date>2020-05-06T18:20:41Z</dc:date>
    <item>
      <title>UCCX REST API for User Roles</title>
      <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4021697#M10971</link>
      <description>&lt;P&gt;I've been using the REST api to develop some custom tools on the UCCX platform.&amp;nbsp; I cannot find an API that allows you to assign the "Supervisor" role to an agent.&amp;nbsp; It's not listed in the official documentation.&amp;nbsp; You cannot add someone as a supervisor to a team without them having the supervisor role initially.&amp;nbsp; Is there a way to accomplish this using an API?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Screenshot is attached showing the section in UCCX I'm referring too&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 20:36:53 GMT</pubDate>
      <guid>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4021697#M10971</guid>
      <dc:creator>tsmith054</dc:creator>
      <dc:date>2020-01-31T20:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: UCCX REST API for User Roles</title>
      <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4021923#M10972</link>
      <description>&lt;P&gt;This is probably the wrong sub-forum of this question.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 20:55:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4021923#M10972</guid>
      <dc:creator>vleijon</dc:creator>
      <dc:date>2020-01-31T20:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: UCCX REST API for User Roles</title>
      <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080146#M10973</link>
      <description>I know it's a bit late, but I moved this message to the Contact Center space.</description>
      <pubDate>Wed, 06 May 2020 01:54:42 GMT</pubDate>
      <guid>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080146#M10973</guid>
      <dc:creator>Anthony Holloway</dc:creator>
      <dc:date>2020-05-06T01:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: UCCX REST API for User Roles</title>
      <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080601#M10976</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at the documentation, I also I do not see an API to assign the supervisor role to a user. There doesn't seem to be a way to assign roles via API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanx,&lt;/P&gt;
&lt;P&gt;Denise&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 15:49:10 GMT</pubDate>
      <guid>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080601#M10976</guid>
      <dc:creator>dekwan</dc:creator>
      <dc:date>2020-05-06T15:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: UCCX REST API for User Roles</title>
      <link>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080725#M10981</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check out this proof of concept to get you started.&amp;nbsp; I provide no support on this solution, please do your due diligence when running random code off the internet on your production systems.&amp;nbsp; ;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;#!/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&amp;amp;wizard=&amp;amp;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})&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2020 18:20:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/contact-center/uccx-rest-api-for-user-roles/m-p/4080725#M10981</guid>
      <dc:creator>Anthony Holloway</dc:creator>
      <dc:date>2020-05-06T18:20:41Z</dc:date>
    </item>
  </channel>
</rss>

