Master Zabbix API Calls with Curl: From Authentication to Historical Data
This guide walks you through using Zabbix's JSON‑RPC API with curl to authenticate, retrieve host and item IDs, fetch historical metrics for specific time ranges, and access additional system information such as version, macros, and media settings.
Overview
This document provides step‑by‑step curl commands for interacting with the Zabbix monitoring system via its JSON‑RPC API. It covers authentication, obtaining host and item identifiers, retrieving historical data, and accessing various system details.
1. Authenticate and obtain a token
Use the user.login method to get an authentication token.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.1.222/zabbix/api_jsonrpc.php2. Get host IDs
Retrieve a specific host ID or all host IDs.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid"],"filter":{"host":"192.168.1.223"}},"auth":"b61b7168931be1065cd722ab44e32d2a","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.phpAll hosts:
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid"]},"auth":"b61b7168931be1065cd722ab44e32d2a","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.php3. Get item IDs for a host
Obtain item IDs for a given host, optionally filtering by key.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":"itemids","hostids":"10119","search":{"key_":"system.cpu.util[,idle]"}},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.phpAll items of the host:
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":["itemids"],"hostids":"10119"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.php4. Retrieve historical values for an item
Fetch all history records for an item ID.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.phpFetch data for a specific time range (e.g., 2014‑05‑01 to 2014‑05‑03). Convert the dates to Unix timestamps (seconds since 1970‑01‑01) before using them.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"time_from":"1398873600","time_till":"1399046400","output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.php5. Get the value at a specific timestamp
Filter the history by the exact clock value.
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"history.get","params":{"history":0,"itemids":["23902"],"time_from":"1398873600","time_till":"1399046400","output":"extend","filter":{"clock":"1399026180"}},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":0}' http://192.168.1.222/zabbix/api_jsonrpc.phpAdditional useful API calls
Get all host information
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":4}' http://192.168.1.222/zabbix/api_jsonrpc.phpCheck Zabbix version
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"apiinfo.version","params":{},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1}' http://192.168.1.222/zabbix/api_jsonrpc.phpGet defined macros
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"usermacro.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1}' http://192.168.1.222/zabbix/api_jsonrpc.phpList user media (alerting methods)
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"usermedia.get","params":{"output":"extend"},"auth":"91aca8c1fe89c89c2e457ab18a28e79b","id":1}' http://192.168.1.222/zabbix/api_jsonrpc.phpNotes
The Zabbix API specifications without the “draft” label are stable for production use. When working with date strings, convert them to epoch seconds (e.g., using a shell command) before inserting them into the time_from and time_till parameters.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
