Add Users in CUCM using Python Script
Add Users in CUCM using Python Script
Hope whosoever reading this post should have basic understanding of python. In this module we will not go deep into python as I am not python expert so some of you may find the script complex but we will try to understand steps being used to achieve the results.
Here we will Add users in CUCM using python script. We will read the user’s details “firstName, lastName, userid” from Users.csv file, will send the SOAP request to CUCM to add the users. print(r.status_code) will print the response code of the request sent [200] in case of successful transaction.
Below is Users.csv file :
import requests ##the requests module allows you to send HTTP requests using Python
import csv ##implements classes to read and write tabular data in CSV format
## The following 3 lines suppresses/ignores the insecure request warnings for unverified https request
import warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter(‘ignore’,InsecureRequestWarning)
keys=[‘UserID’, ‘Fname’, ‘Lname’] ## Create list of headers in Users.csv file
r=open(‘Users.csv’) ## Reading the CSV file
read=csv.DictReader(r)
for DevName in read: ## iterate through each row in the file
values=list(map(DevName.get, keys)) ## Building the List of the values for each header for a particular row. For first user it will look like values=[User1, User1, LUser1]
## Below is the SOAP request that we will send to CUCM to add users with given details “firstName, lastName, userid”
soaprequest=”””<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:ns=”http://www.cisco.com/AXL/API/11.5″>
<soapenv:Header/>
<soapenv:Body>
<ns:addUser>
<user>
<firstName>””” +values[1]+ “””</firstName>
<lastName>””” +values[2]+ “””</lastName>
<userid>””” +values[0]+ “””</userid>
</user>
</ns:addUser>
</soapenv:Body>
</soapenv:Envelope>”””
r=requests.post(“https://cucmip/axl/”, verify=False, auth=(‘username’,’password’), data=soaprequest)
print(r.status_code) ##print the response code of the request sent [200] in case of successful transaction.
import requests ##the requests module allows you to send HTTP requests using Python import csv ##implements classes to read and write tabular data in CSV format ## The following 3 lines suppresses/ignores the insecure request warnings for unverified https requests import warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning warnings.simplefilter('ignore', InsecureRequestWarning) keys=['UserID', 'Fname', 'Lname'] ## Create list of headers in Users.csv file r=open('Users.csv') ## Reading the CSV file read=csv.DictReader(r) for DevName in read: ## iterate through each row in the file values=list(map(DevName.get, keys)) ## Building the List of the values for each header for a particular row. For first user it will look like values=[User1, User1, LUser1] ## Below is the SOAP request that we will send to CUCM to add users with given details "firstName, lastName, userid" soaprequest="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/11.5"> <soapenv:Header/> <soapenv:Body> <ns:addUser> <user> <firstName>""" +values[1]+ """</firstName> <lastName>""" +values[2]+ """</lastName> <userid>""" +values[0]+ """</userid> </user> </ns:addUser> </soapenv:Body> </soapenv:Envelope>""" r=requests.post("https://cucmip/axl/", verify=False, auth=('username','password'), data=soaprequest) print(r.status_code) ##print the response code of the request sent [200] in case of successful transaction.
Hope the document is useful. Please share feedback.
Thank you!!
I have total experience of 5+ years and working in Cisco VoIP since last 4+ years. I have worked on various Cisco applications like CUCM, UCCX, CUC, VGWs, 3rd party SBCs (Sonus and Oracle) with expertise on UCCX. Currently hold active certification is Cisco Certified Specialist – Collaboration Core (CLCOR 350-801).
Hi I am getting below error while trying to run the script.
//can only concatenate str (not “NoneType”) to str// in line 15 here.
Please assist.
thanks for this wonderful article. this helped for sure. If time permits could you please let me know if AXL/XML API available for PCCE and UCCE ?