API PUT Command Not Processing Body Data

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
joelvanos
Posts: 2
Joined: Mon May 04, 2020 11:28 am

API PUT Command Not Processing Body Data

Post by joelvanos »

I am currently using the Nagios XI API to try and automate some tasks. In my testing I found that the POST command would allow me to send data in the body of a curl request, but a PUT command would just ignore all data unless it was passed on the URL. Is this expected behavior or am I doing something wrong? I would like to be able to use the PUT with body data so that I don't have to worry about the URL length issue in this post:
viewtopic.php?p=342340#p342340

Working API Call (URL Parameters):
curl -k -XPUT "https://nagiosxihost/nagiosxi/api/v1/co ... ost1,host2"

Broken API Call (Data in Body):
curl -k -XPUT "https://nagiosxihost/nagiosxi/api/v1/co ... n=service1" -d "host_name=host1,host2"
DoubleDoubleA
Posts: 272
Joined: Thu Feb 09, 2017 5:07 pm

Re: API PUT Command Not Processing Body Data

Post by DoubleDoubleA »

Hi @joelvanos,

I also cannot get -d to work on a PUT with the Nagios XI API. I see in the code that we handle POST and PUT differently, it looks like PUT is expecting all of the arguments in the URL. I'll put in an issue about seeing if we can change the handling of the PUT without breaking what users have come to expect of it. If we can't we'd have to wait for a new version of the API.

Aaron
joelvanos
Posts: 2
Joined: Mon May 04, 2020 11:28 am

Re: API PUT Command Not Processing Body Data

Post by joelvanos »

Thanks. I look forward to any updates.
optionstechnology
Posts: 234
Joined: Thu Nov 17, 2016 11:26 am

Re: API PUT Command Not Processing Body Data

Post by optionstechnology »

Also just FYI because of this put commands cannot process service name changes if the service name has a space in it
DoubleDoubleA
Posts: 272
Joined: Thu Feb 09, 2017 5:07 pm

Re: API PUT Command Not Processing Body Data

Post by DoubleDoubleA »

@optionstechnology I must kindly disagree.

It is possible to use PUT on a service with a space in the name. In the POST you can use the space, but in the PUT you need to put in a "+" where the space is. This is standard url encoding.

Code: Select all

[root@localhost tools]# curl -XPOST "http://192.168.94.133/nagiosxi/api/v1/config/service?apikey=DJY9CkGmHNW3pFk0hgnG2Qug46nWv9BrV3D82fi3DEVW3M3Vgn7vULO5P0BNs2pO&pretty=1" -d "host_name=testapihost&service_description=P ING&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
{
    "success": "Added testapihost :: P ING to the system. Config applied, Nagios Core was restarted."
}
[root@localhost tools]# curl -XPUT "http://192.168.94.133/nagiosxi/api/v1/config/service/?apikey=DJY9CkGmHNW3pFk0hgnG2Qug46nWv9BrV3D82fi3DEVW3M3Vgn7vULO5P0BNs2pO&old_config_name=testapihost&old_service_description=P+ING&pretty=1&display_name=PINGTEST&host_name=localhost&service_description=pLingly&applyconfig=1"                                                                 {
    "success": "Updated testapihost :: pLingly in the system. Config applied, Nagios Core was restarted."
}
In the API docs onboard XI it says:
"This command creates or updates a service object. To update, a host_name or config_name must be specified to find the specific service. If you have special characters in the config_name or service_description and cannot pass it through the path, you can use config/service with the old_config_name=<config_name> and old_service_description=<service_description> URL parameters instead."

Aaron
Post Reply