Looking for some API code to pull back and parse the XML data returned from the /api/computer rest API.
I can pull back the XML, but have having issues picking out a specific element from the XML.
For example show only computer name OS and CPU. I can get all the data from a loop but struggling to parse a specific item
I might be able to post something more this afternoon, but assuming youâve gotten a response already and loaded is as XML (with either lxml or ElementTree), you should be able to navigate the XML result with xpaths, find, or findall
computer_id = computer.find('Computer/Property[@Name="ID"]').text
computer_name = computer.find('Computer/Property[@Name="Computer Name"]').text
computer_os = computer.find('Computer/Property[@Name="OS"]').text
computer_cpu = computer.find('Computer/Property[@Name="CPU"]').text
print(f"{computer_id}, {computer_name}, {computer_os}, {computer_cpu}")
[quote=âJasonWalker, post:2, topic:42945â]
computer_id = computer.find(âComputer/Property[@Name=âIDâ]â).text
âŚ
Jason, thats what I needed, I was trying to pull from Property and was failing in that find. Appreciate the help on this one.
There is a python API for the BigFix REST API here: GitHub - jgstew/besapi: besapi is a Python library designed to interact with the BigFix REST API.
You can install it with: pip install besapi
It makes it very easy to parse the XML using native python objects, or as LXML, either one.
I have also been working on adding higher level functions to it for various purposes beyond it just being a simple REST API wrapper.
The besapi also provides an interactive bescli for working with the besapi. I am tempted to split them into 2 separate projects in the future though.
See an example python that uses besapi here: generate_bes_from_template/examples/generate_uninstallers.py at master ¡ jgstew/generate_bes_from_template ¡ GitHub