Ad Widget

Collapse

Zabbix API: item.get with search function doesn't work.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar.cacciotti
    Junior Member
    • Jul 2021
    • 25

    #1

    Zabbix API: item.get with search function doesn't work.

    Hello.
    I'm trying to get a precise ITEM by using the associated trigger id.
    I noticed that "search" function never works and the response is giving all the items of the selected host instead of the single item.
    Env: Zabbix 7.4.2
    Usr: Admin (token)

    I followed the manual: https://www.zabbix.com/documentation...rence/item/get

    TEST n1: USING TRIGGERIDS
    Code:
    get_response=$(curl -sk -X POST $URL -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH" -d '
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "output": "extend",
        "hostids": "10765",
        "with_triggers": true,
        "search": {
          "triggerids": "123456"
        },
        "sortfield": "name"
      },
      "id": 1
    }')

    TEST n2: USING ITEMIDS (just as debug pourpose)
    Code:
    get_response=$(curl -sk -X POST $URL -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH" -d '
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "output": "extend",
        "hostids": "10765",
        "with_triggers": true,
        "search": {
          "itemids": "123456"
        },
        "sortfield": "name"
      },
      "id": 1
    }')
    TEST n3: USING non-existent Trigger ID (just as debug pourpose)
    Code:
    get_response=$(curl -sk -X POST $URL -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH" -d '
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "output": "extend",
        "hostids": "10765",
        "with_triggers": true,
        "search": {
          "triggerids": "1"
        },
        "sortfield": "name"
      },
      "id": 1
    }​')


    TEST n4: DROPPING THE WHOLE search FUNCTION
    Code:
    get_response=$(curl -sk -X POST $URL -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH" -d '
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "output": "extend",
        "hostids": "10765",
        "with_triggers": true,
        },
        "sortfield": "name"
      },
      "id": 1
    }​')


    RESULT:
    Each test is giving the same output (just a full dump of all items of the Host 10765).

    Does someone knows what's wrong in my tests?
    Should I consider this is a bug

    Thanks to anyone
    Last edited by omar.cacciotti; 20-09-2025, 20:27.
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    For "search" reference the Common "get" parameters.
    Essentially you need to specify one of params the item has. So if you doing item.get you need to use params from item object. It does not contain neither "itemids" nor "triggerids". It has "itemid" (without -s). That one you can use to search by itemid.

    In regard "triggerids". It's not part of item object, but it's a parameter of item.get function. So you don't need to put it under search section. Use directly as method param. So something like

    Code:
    get_response=$(curl -sk -X POST $URL -H "Content-Type: application/json" -H "Authorization: Bearer $AUTH" -d '
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "output": "extend",
        "hostids": "10765",
        "with_triggers": true,
        "triggerids": "123456",
        "sortfield": "name"
      },
      "id": 1
    }')
    Hope it helps

    Comment

    Working...