I definitely suggest you to use the downtime example in the REST API documentation:
#!/usr/bin/env python3
import pprint
import requests
HOST_NAME = "localhost"
SITE_NAME = "production"
API_URL = f"http://{HOST_NAME}/{SITE_NAME}/check_mk/api/1.0"
USERNAME = "automation"
PASSWORD = "test123"
session = requests.session()
session.headers['Authorization'] = f"Bearer {USERNAME} {PASSWORD}"
session.headers['Accept'] = 'application/json'
resp = session.post(
f"{API_URL}/domain-types/downtime/collections/service",
headers={
"Content-Type": 'application/json', # (required) A header specifying which type of content is in the request/response body.
},
# This schema has multiple variations. Please refer to
# the 'Payload' section for details.
json={
'start_time': '2017-07-21T17:32:28Z',
'end_time': '2017-07-21T17:32:28Z',
'recur': 'hour',
'duration': 3600,
'comment': 'Security updates',
'downtime_type': 'service',
'host_name': 'example.com',
'service_descriptions': [
'CPU utilization', 'Memory'
]
},
)
if resp.status_code == 200:
pprint.pprint(resp.json())
elif resp.status_code == 204:
print("Done")
else:
raise RuntimeError(pprint.pformat(resp.json()))
more examples can be found in your check_mk installation → Help → REST API documentation