Hi.
The script looks like this:
The output is:
As can be seen the first authorization request passes but the second request "----" does not pass, although the request was for the documents and errors there may be no.
Help, why the error?
==============================
I found a solution to the problem itself
after the last element of the array must not be a comma
The script looks like this:
PHP Code:
$url = "http://***/zabbix/api_jsonrpc.php";
function send_request($url,$json) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
curl_setopt($ch, CURLOPT_USERPWD, "***:***");
$result=curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
$json = '{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "admin",
"password": "***"
},
"id":1
}';
$res = send_request($url,$json);
$auth = $res->result;
var_dump($auth);
$json = '{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "domain.ru",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "192.168.0.1",
"dns": "domain.ru",
"port": "10050"
}
],
"groups": [
{
"groupid": "9"
}
],
"templates": [
{
"templateid": "10130"
}
],
},
"auth": "'.$auth.'",
"id":1
}';
$res = send_request($url,$json);
var_dump($res);
PHP Code:
string(32) "c96ceaf1051c3410a43f73541f8c1c05"
object(stdClass)#2 (3) {
["jsonrpc"]=>
string(3) "2.0"
["error"]=>
object(stdClass)#3 (3) {
["code"]=>
int(-32600)
["message"]=>
string(16) "Invalid Request."
["data"]=>
string(34) "JSON-rpc version is not specified."
}
["id"]=>
NULL
}
Help, why the error?
==============================
I found a solution to the problem itself
after the last element of the array must not be a comma