Source
'request' => '{"jsonrpc": "2.0", "method": "apiinfo.version", "params": {}, "id": 1, "foo": "bar"}',
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
require_once dirname(__FILE__).'/../include/CAPITest.php';
class testJSONRPC extends CAPITest {
public static function json_rpc_data() {
return [
// rpc call with invalid JSON
[
'request' => '{"jsonrpc": "2.0", "method": "foobar, "params": "bar", "baz]',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32700,
'message' => 'Parse error',
'data' => 'Invalid JSON. An error occurred on the server while parsing the JSON text.'
],
'id' => null
]
],
// rpc call Batch, invalid JSON
[
'request' =>
'['.
'{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},'.
'{"jsonrpc": "2.0", "method"'.
']',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32700,
'message' => 'Parse error',
'data' => 'Invalid JSON. An error occurred on the server while parsing the JSON text.'
],
'id' => null
]
],
// rpc call with an empty Array
[
'request' => '[]',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32600,
'message' => 'Invalid request.',
'data' => 'The received JSON is not a valid JSON-RPC request.'
],
'id' => null