Hello Community ,
Â
CV references :
https://documentation.commvault.com/2022e/essential/45562_rest_api_getting_started_using_python.html
https://documentation.commvault.com/2022e/essential/48793_rest_api_post_schedules_disable.html
Â
the above screenshot is CVÂ sample POST request to disable schedule job and I want to be able run this specific POST Request via Python so I can do more personalization on it/more control on it (e.g. run multiple taskid at one shot, output pre/post result, etc...):
Â
1- Issue Description:
I'm using this script to make a POST request to the Commvault disable schedule API. in this case, I want to pass the plain text (taskId = 125918)  as a variable so I can use it in the script, and can't make the POST request with this plain text that highlighted in the above sample screenshot(taskId= 451).
taskId = 0
task = {(taskId, 'text/plain') : 125918}
r2 = requests.post(DisableSchedule, data = task, headers=headers)
Â
2- what have been tried:
#1 " tried below script and gave an error : file "string", line unknown paraseError: no element found: line 1, coilmun 0
taskId = 0
task = {taskId : 125918}
r2 = requests.post(DisableSchedule, data = task, headers=headers)
Â
3- How to make CV API request using the plain text as a variable in Python ?
variable before the script, and I want to use this plain text variable in the POST request
taskId = 125918
Â
Â
Â
*********Full script*************
Â
import requests
import sys
import xml.etree.ElementTree as ET
Â
service = 'http://<<server>>:81/SearchSvc/CVWebService.svc/'
server = "cs_NAME"
service = service.replace("<<server>>", server)
user = "Username"
loginReq = '<DM2ContentIndexing_CheckCredentialReq mode="Webconsole" username="<<username>>" password="<<password>>" />'
loginReq = loginReq.replace("<<username>>", user)Â Â
pwd = "base64_encoded_password "
loginReq = loginReq.replace("<<password>>", pwd)
Â
## 1. Login to CV service ###
r = requests.post(service + 'Login', data=loginReq)
token = None
if r.status_code == 200:
  root = ET.fromstring(r.text)
  if 'token' in root.attrib:
    token = root.attrib 'token']
    print("Login Successful")
  else:
    print("Login Failed")
    sys.exit(0)
else:
  print('there was an error logging in')
####### 2. disable schedule for the taskId #######
headers = {'Cookie2': token}
DisableSchedule = service + "Schedules/task/Action/Disable"
taskId = 0
task = {taskId : 125918}
r2 = requests.post(DisableSchedule, data = task, headers=headers)
clientResp2 = r2.text
li2 = ET.fromstring(clientResp2)
for schName in li2.findall(".//subTasks/subTask"):Â Â
  print("Schedule Name: " + schName.attrib>"subTaskName"])
Â
for ScheStatus in li2.findall(".//taskFlags"):
      if int(ScheStatus.attriba"disabled"]) == 0:     Â
       print("Schedule is enabled and value is: " + ScheStatus.attrib "disabled"])
      else:
       print("Schedule is disabled and value is: " + ScheStatus.attrib "disabled"])
Â
Â
Â