{"id":38514,"date":"2023-08-20T04:47:08","date_gmt":"2023-08-20T04:47:08","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=38514"},"modified":"2023-08-20T04:47:10","modified_gmt":"2023-08-20T04:47:10","slug":"zabbix-tutorials-working-with-zabbix-api","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/zabbix-tutorials-working-with-zabbix-api\/","title":{"rendered":"Zabbix Tutorials: Working with Zabbix API"},"content":{"rendered":"\n<p>Here is a short tutorial on how to use the Zabbix API:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create an API user:<\/strong>&nbsp;You need to create an API user in Zabbix before you can start using the API. To do this, go to&nbsp;<strong>Administration<\/strong>&nbsp;&gt;&nbsp;<strong>Users<\/strong>&nbsp;and click on the&nbsp;<strong>Create User<\/strong>&nbsp;button. In the&nbsp;<strong>User<\/strong>&nbsp;tab, select the&nbsp;<strong>API<\/strong>&nbsp;role and enter a username and password for the user.<\/li>\n\n\n\n<li><strong>Get an API token:<\/strong>&nbsp;Once you have created an API user, you need to get an API token for the user. To do this, go to&nbsp;<strong>Administration<\/strong>&nbsp;&gt;&nbsp;<strong>Users<\/strong>&nbsp;and click on the&nbsp;<strong>API Tokens<\/strong>&nbsp;tab. Click on the&nbsp;<strong>Create Token<\/strong>&nbsp;button and enter a name for the token.<\/li>\n\n\n\n<li><strong>Use the API:<\/strong>\u00a0Now that you have an API token, you can start using the API. The Zabbix API documentation provides a detailed overview of the API. You can also use the Zabbix API Explorer to test the API calls.<\/li>\n<\/ol>\n\n\n\n<p>Here are some examples of how to use the Zabbix API:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">To get a <span class=\"hljs-keyword\">list<\/span> of hosts:\r\ncurl -X GET -H <span class=\"hljs-string\">\"Authorization: Bearer &lt;API_TOKEN&gt;\"<\/span> https:<span class=\"hljs-comment\">\/\/zabbix.example.com\/api\/v1\/host<\/span>\r\nTo create a <span class=\"hljs-keyword\">new<\/span> item:\r\ncurl -X POST -H <span class=\"hljs-string\">\"Authorization: Bearer &lt;API_TOKEN&gt;\"<\/span> -H <span class=\"hljs-string\">\"Content-Type: application\/json\"<\/span> -d <span class=\"hljs-string\">'{\r\n    \"hostid\": 10001,\r\n    \"key\": \"system.cpu.load&#91;all]\",\r\n    \"type\": \"0\",\r\n    \"value_type\": \"0\",\r\n    \"multiplier\": 1,\r\n    \"units\": \"percent\"\r\n}'<\/span> https:<span class=\"hljs-comment\">\/\/zabbix.example.com\/api\/v1\/item<\/span>\n\n<span class=\"hljs-comment\"># To get the list of host<\/span>\ncurl --request POST   --url <span class=\"hljs-string\">'http:\/\/54.197.199.105\/zabbix\/api_jsonrpc.php'<\/span>   --header <span class=\"hljs-string\">'Authorization: Bearer bc2dde7c3014a0cd77d662b40225bc634e922e7e4146a9f3a7da20fcf389f696'<\/span>   --header <span class=\"hljs-string\">'Content-Type: application\/json-rpc'<\/span>   --data @data.json<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>Here is a short tutorial on how to use the Zabbix API: Here are some examples of how to use the Zabbix API:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-38514","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/38514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=38514"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/38514\/revisions"}],"predecessor-version":[{"id":38515,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/38514\/revisions\/38515"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=38514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=38514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=38514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}