Logging in

Before we can perform any useful operations through the API, we must log in. Our JSON string would be as follows:

$ json='{"jsonrpc":"2.0","method":"user.login","id":2,"params":{"user":"Admin","password":"zabbix"}}'  

Now, run the curl command to get the API version. In all further API requests, we'll only change the json variable and then reuse the same curl command:

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

In this case, assuming a correct username and password, it should return the following:

{"jsonrpc":"2.0","result":"df83119ab78bbeb2065049412309f9b4","id":2} 
We use the request ID 2. That wasn't really required—we could've used 3, 5, or 1013. We could've used 1; all requests have a very obvious response, so we don't care about the ID at all. The response still did have the same ID as our request, 2.

This response also has an alphanumeric string in the result property, which is very important for all further work with the API. This is an authentication token or session ID that we'll have to submit with all subsequent requests. For our tests, just copy that string and use it in the json variable later.

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

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