- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 07:03 PM
Was curious if anyone has an example or any success with using JSON to interact with the UCCX REST API.
I am following this guide: https://developer.cisco.com/docs/contact-center-express/#!modify-application/modify-application
It says it supports both XML and JSON, but I can't get JSON to work, XML works ok even though you have to send the whole configuration it seems, you can't just modify one field alone. However, I can't get JSON to work at all.
I tested using the Cisco sandbox and the main thing I want to do is update a script variable string field that the application uses.
Code:
import requests
from requests.auth import HTTPBasicAuth
import xmltodict
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
username = '*********'
password = '*********'
xml_str = """<application>
<ScriptApplication>
<script>SCRIPT[override_script.aef]</script>
<scriptParams>
<name>override_status</name>
<value>"open"</value>
<type>java.lang.String</type>
</scriptParams>
</ScriptApplication>
<id>1</id>
<applicationName>override</applicationName>
<type>Cisco Script Application</type>
<description>mydescription</description>
<maxsession>10</maxsession>
<enabled>true</enabled>
</application>"""
def convert_xml_to_json(xml_str):
x = xmltodict.parse(xml_str)
return x
myjson = convert_xml_to_json(xml_str)
print(json.dumps(myjson, indent=4))
# Update using XML
def change_application_parameter_xml():
headers = {"Accept": "application/xml", "Content-Type": "application/xml"}
url = "https://hq-uccx.abc.inc/adminapi/application/override"
res = requests.put(url, auth=HTTPBasicAuth(username, password), headers=headers, data=xml_str, verify=False)
print('XML Done')
print(res.text)
change_application_parameter_xml()
# Update using JSON
def change_application_parameter_json():
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = "https://hq-uccx.abc.inc/adminapi/application/override"
res = requests.put(url, auth=HTTPBasicAuth(username, password), headers=headers, json=myjson, verify=False)
print('JSON Done')
print(res.json())
change_application_parameter_json()
Result:
MacBook-Pro ~ % /usr/local/bin/python3 /Users/Desktop/uccx_testing.py
{
"application": {
"ScriptApplication": {
"script": "SCRIPT[override_script.aef]",
"scriptParams": {
"name": "override_status",
"value": "\"open\"",
"type": "java.lang.String"
}
},
"id": "1",
"applicationName": "override",
"type": "Cisco Script Application",
"description": "mydescription",
"maxsession": "10",
"enabled": "true"
}
}
XML Done
JSON Done
{'apiError': [{'errorData': '', 'errorType': 'InvalidInput'}]}
MacBook-Pro ~ %
Thanks!
Solved! Go to Solution.
- Labels:
-
UCCX
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 11:24 PM - edited 01-26-2024 01:34 AM
Hey.
i have never got it to work with json payload.
an yes - you have to send the whole payload in you request
Thanks, Thomas G. J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 11:24 PM - edited 01-26-2024 01:34 AM
Hey.
i have never got it to work with json payload.
an yes - you have to send the whole payload in you request
Thanks, Thomas G. J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2024 09:02 AM
Thanks for the conformation on both.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2024 06:28 AM
My preference has been to use the etree functions from the lxml library. There are functions to convert the etree back to XML to send back to the UCCX host.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2024 09:06 AM
Thank you for this idea Elliot, I'll have to try this out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2024 11:28 AM
I think at one point I got one or two to work, but it was very inconsistent and not worth the trouble. The XML schema is documented and really not that bad.
david
