This episode opens up full Zabbix automation via the JSON-RPC API: authentication with tokens, host, item, trigger, and alert operations, plus scripts with curl and Python pyzabbix, along with zabbix-cli and Terraform provider integrations.

You've seen curl calls to /api_jsonrpc.php many times in previous episodes. Episode 14 opens that box fully: the Zabbix API is the automation gateway that turns the entire frontend — hosts, items, triggers, alerts — into programmable objects. Everything you can do through the UI can be done through the API.
This capability changes how teams work. Host provisioning, configuration synchronization, and report generation can be run by pipelines instead of humans clicking through the frontend. This episode also introduces three tools that wrap the API: curl, Python with pyzabbix, and Terraform.
The Zabbix API follows the JSON-RPC 2.0 protocol. All requests are sent as POST to the /api_jsonrpc.php endpoint with this format:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {},
"id": 1,
"auth": "<token>"
}The method field defines the operation, params carries the arguments, and auth carries the authentication token. The command curl -s -X POST http://localhost/api_jsonrpc.php from previous episodes was exactly this kind of request.
The recommended way to authenticate automation is an API token created per user in the Users → API tokens menu. The token replaces the password and can have an expiration. Once created, the token is used as the auth value in every request.
To check whether the endpoint is alive, call the apiinfo.version method:
curl -s -X POST http://localhost/api_jsonrpc.php \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"apiinfo.version","id":1,"params":{}}'A response like {"result":"7.0.29"} means the API endpoint is alive. This method doesn't require authentication and is the simplest health check.
The API uses the <object>.<action> naming pattern: host.get, host.create, item.get, trigger.get, and so on. Here's an example of fetching the list of hosts along with their host groups:
curl -s -X POST http://localhost/api_jsonrpc.php \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid","host"],"selectGroups":["name"]},"id":1,"auth":"<token>"}'The parameter selectGroups is an example of API syntax for fetching referenced objects — a pattern used in many methods to enrich query results.
The API also exposes operational data. For notification audits, alert.get fetches alert history, and event.get fetches the list of problem events. These are useful for building external reports or integrating with ticketing systems.
pyzabbix is a Python client for the Zabbix API. Install it, then write a simple script:
pip install pyzabbixfrom pyzabbix import ZabbixAPI
zapi = ZabbixAPI("http://localhost")
zapi.login(user="automation", password="StrongPassword")
hosts = zapi.host.get(output=["host"], selectGroups=["name"])
for h in hosts:
print(h["host"])The script above logs into the API and prints the host list. zapi.host.get(output=["host"]) returns host objects ready to be processed in Python.
zabbix host list.zabbix/zabbix lets hosts, host groups, and templates be managed as code (Infrastructure as Code).resource "zabbix_host" "app01" {
host = "app01.example.com"
hostgroup_name = "Linux servers"
}The zabbix_host resource above defines one host in Terraform. This way, the entire Zabbix configuration can be reviewed, versioned, and deployed reproducibly.
Tip
Use API tokens with the lowest permissions the script needs. Automation running with a Super admin account is a huge risk — scope tokens to the work that must be done.
Some patterns that keep automation safe:
get before create or update.Episode 14 opened up automation: a JSON-RPC-based Zabbix API with API tokens, host, item, trigger, and alert operations, and three practical tools — curl, Python pyzabbix, and Terraform — for managing Zabbix as code.
Key takeaways:
/api_jsonrpc.php.<object>.<action> pattern applies to hosts, items, triggers, alerts, and more.In the next episode 15 we'll discuss authentication, RBAC, and security hardening — authentication with built-in users, LDAP, SAML SSO, and 2FA, role- and permission-based access control, and hardening with TLS/PSK, an HTTPS reverse proxy, and security patches.