Need to run rest api call through Python

Please help me with a rest api call to run with python, the query is to get the baseline using its name. How to wrap this query to run through python:
(.\iem.exe get query --relevance="(ID of it) of BES Baselines whose (Name of it is “”"""$searchstring""""""")") -replace ‘[\x00-\x1f]’,’’

Thank you!!

You should checkout the examples on the developer site using requests. https://developer.bigfix.com/rest-api/examples/#python

Here is a quick example for your query:

import json
import requests

search_string = input('Search for: ').lower()

r = requests.get(f'https://bigfixServer:52311/api/query?output=json&relevance=(id of it) of bes baselines whose (name of it as string as lowercase contains "{search_string}"', verify=False, auth=('yourusername', 'yourpassword'))
  
data = json.loads(r.content)

for id in data['result']:
    print(f'ID: {id}')
4 Likes

without the json.

import requests
from xml.etree import ElementTree
from lxml import etree
import sys,traceback

import urllib3
urllib3.disable_warnings()

reload(sys)
sys.setdefaultencoding(‘utf8’)
r=requests.get('https://xyz:52311/api/query?relevance=( (names of it, operating systems of it,values of results from (BES Property “BES Client Version”) of it) of members of bes computer groups whose ( name of it = “Unix Servers All”) ) ', verify=False,auth=(‘user’, ‘pwd’))
print(r.text)

tree2 = ET.fromstring(r.text)
result=tree2.findall(‘.//QueryResult’)
final_stmt=“”
if result:
for fixlet in tree2.findall(‘.//QueryResult’):
computername=fixlet.find(“ComputerName”).text
result=fixlet.find(“Result”).text
final_stmt=computername+“,”+result
print(final_stmt)

3 Likes

Many Thank You!! It worked for us. :slight_smile: