confirm/PhpZabbixApi

Error on serviceCreate

06chaynes opened this issue · 4 comments

When I call serviceCreate as shown below I get an error:

$serviceGroupCreate = $api->serviceCreate([
'name' => 'test,
'algorithm' => 1,
'showsla' => 1,
'goodsla' => 99.90,
'sortorder' => 1,
'parentid' => 1
]);

Error:
Exception in ZabbixApiAbstract.class.php line 366:
API error -32602: Wrong fields for service "test".

Removing the name column of course returns the error:
API error -32602: Empty name.

I just found the cause of this. I had previously added this a few lines above the call and forgot about it:

$api->setDefaultParams(array(
'output' => 'extend'
));

It was sending this in the call which caused that error to throw. After removing it the call worked as expected.

Hi.

Ah OK! So the output param is not allowed in the API call, right?
Shall I close the issue?

Cheers
Domi

That would be the case yes, as long as you are ok with this behavior I think this would be fine to close. Adding a note on the subject somewhere in the docs may be beneficial though.

I think the behaviour of the PhpZabbixApi is fine, because it works as expected. I checked the official API docs and there's no output parameter, so I think Zabbix behaves fine too :)

PhpZabbixApi will always add the default params to all coming requests and there's (currently) no way to check if the default params are valid or not. The developer is always in charge of the passed parameters.

However, I'll probably add a note about default params in the docs, that shouldn't harm ;)