Page 1 of 1

[API] Possible to add multiple contacts when creating a service?

Posted: Mon May 20, 2024 1:07 pm
by ibdv
Hello,

I couldn't find an answer for this, but it seems that when creating a service (or updating one via put) the contact is only set as the last value given in a list. The following code creates the service:

body = {
"host_name": "edge",
"service_description": "PEERING_123",
"check_command": "bgp_edge_check!edge01!edge02!!!!1!100!snmp",
"max_check_attempts": "3",
"check_period": "24x7",
"check_interval": "3",
"retry_interval": 3,
"notification_period": "24x7",
"notification_interval": "60",
"contacts": ["slack_support", "support"],
}
requests.post(url="https://10.0.0.50/nagiosxi/api/v1/config/service/", data=body, params=params, verify=False)


But it only has one contact "support" when I open it in the GUI. Is it possible to set multiple contacts via the API?

Re: [API] Possible to add multiple contacts when creating a service?

Posted: Mon May 20, 2024 2:35 pm
by jmichaelson
The API reference documentation at /nagiosxi/help/ uses query parameters as its examples. While it doesn't document how to go about adding multiple contacts to a host in this way, I'd try using some of the examples from /nagiosxi/help/api-common-solutions.php as guides, and using something like &contacts[]=slack_support&contacts[]=support.

Re: [API] Possible to add multiple contacts when creating a service?

Posted: Mon May 20, 2024 2:56 pm
by snapier3
I do this a ton in Python...

Modify your list format
"contacts": ["slack_support", "support"],
Change to this and see what you get ;)

Code: Select all

"contacts": ["slack_support, support"],
--SN

Re: [API] Possible to add multiple contacts when creating a service?

Posted: Mon May 20, 2024 9:27 pm
by ibdv
snapier3 wrote: Mon May 20, 2024 2:56 pm I do this a ton in Python...

Modify your list format
"contacts": ["slack_support", "support"],
Change to this and see what you get ;)

Code: Select all

"contacts": ["slack_support, support"],
--SN
Oh my word, this did the trick it looks like. Thank you!