Operations 9 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Zabbix API Calls with Curl: From Authentication to Historical Data

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.php

2. 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.php

All 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.php

3. 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.php

All 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.php

4. 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.php

Fetch 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.php

5. 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.php

Additional 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.php

Check 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.php

Get 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.php

List 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.php

Notes

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

APIcURLZabbixJSON-RPC
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.