[ZBX-23143] API item.get search Created: 2023 Jul 24  Updated: 2023 Jul 28

Status: Confirmed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 6.0.19, 6.4.3, 6.4.4
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Evgeny Semerikov Assignee: Zabbix Development Team
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello!

According to documentation (https://www.zabbix.com/documentation/current/en/manual/api/reference_commentary#common-get-method-parameters)

search object Return results that match the given pattern (case-insensitive).
 
Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE "%…%" search.
 
Works only for string and text fields.

I'm try to search items with this request:

{
	"jsonrpc": "2.0",
	"method": "item.get",
	"params": {
		"output": [
			"itemid",
			"key_",
			"name",
			"units"
		],
		"hostids": "10584",
		"search": {
			"key_": [
				"icmpping",
				"common.health"
			]
		}
	},
	"id": 1,
	"auth": "token"
}

and get empty response:

{
	"jsonrpc": "2.0",
	"result": [],
	"id": 1
}

But if I add ("searchByAny": true), then I got answer what I want, but with more items (like if searchWildcardsEnabled=true)

{
	"jsonrpc": "2.0",
	"method": "item.get",
	"params": {
		"output": [
			"itemid",
			"key_",
			"name",
			"units"
		],
		"hostids": "10584",
		"search": {
			"key_": [
				"icmpping",
				"common.health"
			]
		},
		"searchByAny": true
	},
	"id": 1,
	"auth": "token"
}

Seems simple array of items is not working properly.



 Comments   
Comment by Aigars Kadikis [ 2023 Jul 26 ]

Thank you for contacting Zabbix. If you search by one metric, by using this approach:

{
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
        "output": [
            "hostid",
            "itemid",
            "key_",
            "name",
            "units"
        ],
        "searchWildcardsEnabled":true,
        "search": {
            "key_": [
                "icmpping"
            ]
        }
    },
    "id": 1,
    "auth": "{{auth}}"
}

Is the output is satisfying? Nothing too much?

Still, this API call does not support an array of item keys, which is a bug. And logic of "searchWildcardsEnabled" setting seems to be reversed.

Confirm if I understand the use case: you are looking for a single API call which allows to pass 2 precise item keys.

Comment by Aigars Kadikis [ 2023 Jul 27 ]

Final conclusion is: it's not possible to specify an array of different item keys in the search:

        "search": {
            "key_": [
                "system.uname", "proc.num", "agent.version"
            ]
        }

It looks like underneath the hood it works like:

SELECT hosts.hostid, items.itemid, items.key_ FROM items, hosts
WHERE items.hostid=hosts.hostid
AND items.key_ LIKE '%system.uname%'
AND items.key_ LIKE '%proc.num%'
AND items.key_ LIKE '%agent.version%';

Where it should be like:

SELECT hosts.hostid, items.itemid, items.key_ FROM items, hosts
WHERE items.hostid=hosts.hostid
AND (items.key_ LIKE '%system.uname%'
OR items.key_ LIKE '%proc.num%'
OR items.key_ LIKE '%agent.version%');

Either it's a bug or documentation task or works by design because in GUI, we cannot search multiple item keys at the same time.

Comment by Evgeny Semerikov [ 2023 Jul 28 ]

Also, in my case request like

{    "jsonrpc": "2.0",    "method": "item.get",    "params": {        "output": ["itemid", "key_", "name", "units"],        "hostids": "111111",        "search": {            "key_": ["icmpping", "someitemkey"]        },        "searchByAny": true    },    "id": 1,    "auth": "token"}

returns this

{    "jsonrpc": "2.0",    "result": [        {            "itemid": "11111",            "key_": "someitemkey",            "name": "Item name",            "units": ""        },        {            "itemid": "11111111",            "key_": "icmppingloss",            "name": "ICMP loss",            "units": "%"        },        {            "itemid": "11111",            "key_": "icmpping",            "name": "ICMP ping",            "units": ""        },        {            "itemid": "11111",            "key_": "icmppingsec",            "name": "ICMP response time",            "units": "s"        }    ],    "id": 1}

In this output is correct only "someitemkey" and "icmpping" as I suppose, but other "icmpping*" is must be displayed if wildcard param provided.

Generated at Wed Jun 03 19:50:40 EEST 2026 using Jira 10.3.18#10030018-sha1:5642e4ad348b6c2a83ebdba689d04763a2393cab.