Showing results for 
Show  only  | Search instead for 
Did you mean: 


Example of How to Use Python with SVR/Research API to Create Watchlists.



You may run python from RHEL. Here are some steps to install Python on RHEL.

1. Install the pip from SCL as root

# subscription-manager repos --enable rhel-server-rhscl-7-rpms

# yum install python27-python-pip

2. Switch to a normal user and check the pip

# scl enable python27 bash

# which pip

# pip -V

3. Install requests modules with pip and run .py script

# pip install requests

# python

Example Code:

import requests
import json

session = requests.Session()
session.headers.update({'Authorization': 'Token TOKENVALUEHERE', 'Content-Type': 'application/json',
'Accept': 'application/json', 'Host': '', 'Accept-Encoding': 'gzip, deflate'})

#Create Watchlist - Uncommment below to Create.
# response ='', json={'enabled': True,'receive_all':False,'products':[],'vendors':[],'advisories_need_approval':False,'ticket_threshold_level':6,'notification_level_email':6,'notification_level_sms':1,'ignored':[],'selected':[],'custom_cr': None, 'custom_ir': None,'custom_ar': None,'product_releases':[60497],'name':'TEST2','group': None})

# print(response)
# print (json.dumps(response.json(), indent=4, sort_keys=True))

#Modify Watchlist - REPLACE 14 in both URL and payload with the Watchlist ID to update. Modify the json payload with changes to be made.
response = session.put('', json={"id":14,"enabled":True,"receive_all":False,"products":[],"vendors":[],"advisories_need_approval":False,"ticket_threshold_level":6,"notification_level_email":6,"notification_level_sms":1,"custom_cr":None,"custom_ir":None,"custom_ar":None,"host_group_id":None,"product_releases":[60497,46340],"group":1,"name":"TEST6"})

print (json.dumps(response.json(), indent=4, sort_keys=True))


#Delete Watchlist - Uncomment below and REPLACE 16 in both URL and payload with the Watchlist ID to delete.
# response = session.delete('', json={"id":16})


Additional Info:

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Mar 09, 2021 02:37 PM
Updated by: