# Zabbix API (JSON RPC) with Powershell

## method apiinfo.version
```powershell
Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";method="apiinfo.version";params=@{};id=1} | ConvertTo-Json)
```

## method user.login
```powershell
(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";method="user.login";params=@{user="UserName";password="Password"};id=1} | ConvertTo-Json)).result
```

## method host.get

### Search by name
```powershell
(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{search=@{name="myhost"};output=@("hostid","name","status")}} | ConvertTo-Json)).result
```

### Filter by name
```powershell
(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{filter=@{name="myhostname"};output=@("hostid","name","status")}} | ConvertTo-Json)).result
```

### List hosts' items

```powershell
(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{search=@{name="myhost"};output=@("name");selectItems="extend"}} | ConvertTo-Json)).result.items | Select-Object name,key_
```

## method item.get

### List items which "key_" includes "sensor.status" from 5 hosts

```powershell
(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="item.get";params=@{hostids=@(200200000000001;200200000000002;200200000000003;200200000000004;200200000000005);search=@{key_="sensor.status"}}} | ConvertTo-Json)).result | Select-Object hostid,name,lastvalue
```

## Reference
* https://www.zabbix.com/documentation/current/manual/api
* https://github.com/zabbix/zabbix