Hi please try the following to get the etag:
HOST_NAME = "yourhost"
SITE_NAME = "yoursite"
API_URL = f"https://{HOST_NAME}/{SITE_NAME}/check_mk/api/1.0"
USERNAME = "youruser"
PASSWORD = "yoursecret"
HOSTNAME = "hostnameToQuery"
query_string = urllib.parse.urlencode({
})
request = urllib.request.Request(
f"{API_URL}/objects/host_config/{HOSTNAME}?{query_string}",
method="GET",
headers={
"Authorization": f"Bearer {USERNAME} {PASSWORD}",
"Accept": "application/json",
},
)
response = urllib.request.urlopen(request)
if response.status == 200:
etag = str(response.headers["ETag"])
elif response.status == 204:
print("Done")
else:
raise RuntimeError(response.read())
You can then use the etag variable for the “If-Match” Header.