Simple operations

The Zabbix API is request-response-based. We send a request and get a response—either the data we requested or a success/failure indicator. Let's look at some simple, practical examples of what we can do with the API. We'll use simple curl requests to the API. Let's try this on the Zabbix server:

$ curl -s -X POST -H 'Content-Type: application/json-rpc' -d '' http://127.0.0.1/zabbix/api_jsonrpc.php  

In this request, note the following:

  • We use the POST method and send the JSON string with the -d parameter—empty for now.
  • We also specify the -s parameter, which enables silent or quiet mode and suppresses progress and error messages.
  • The URL is the Zabbix API endpoint, api_jsonrpc.php. This will be the same for all API requests. Additionally, we specify the content type to be application/json-rpc. This is required. If omitted, the Zabbix API will return an empty response, which doesn't help much. The request we issued should return a response like this:
{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request.","data":"The received JSON isn't a valid JSON-RPC Request."},"id":null} 

That didn't work, but at least there's an error message. Let's proceed with more valid requests now.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.125.7