Ad Widget

Collapse

Efficient use of the API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wamsterdam
    Member
    • Apr 2013
    • 34

    #1

    Efficient use of the API

    Hi,

    I'm trying to use the API to put together a small report, but I have my doubts in myself using it efficiently. I'd like to retrieve some item information for all hosts using template X.

    So first I use the API template.get to retrieve all hosts connected to template X. Then I loop through the hosts one by one to retrieve the item information using item.get. That's an API request for each item for each host. So for 10 hosts with 5 items each, that's 50 requests. Wouldn't it be more efficient to request all 5 items per host in a single request? If so, how do I accomplish that?

    TIA,
    Wouter
  • steveboyson
    Senior Member
    • Jul 2013
    • 582

    #2
    Don't know if that helps:


    It seems to me that it can return more than one item.

    Comment

    • wamsterdam
      Member
      • Apr 2013
      • 34

      #3
      steveboyson,

      As shown in the example at the page you mentioned, a "search" method is used to retrieve all keys with value 'system'. In my case, I already know which keys I need to retrieve. Directly querying the key as I do now, would be more database-efficient than first searching for the keys and than query their values, I assume?

      Wouter

      Comment

      • MaxM
        Member
        • Sep 2011
        • 42

        #4
        The itemids param can take more than a single itemid. In fact, it can take an array. E.g.

        {
        "jsonrpc": "2.0",
        "method": "item.get",
        "params": {
        "output": "extend",
        "itemids": ["10135", "10222", "140812"],
        "sortfield": "name"
        },
        "auth": "038e1d7b1735c6a5436ee9eae095879e",
        "id": 1
        }

        You do not even need to use the hostid if you know the itemid, the itemid field is unique.

        Comment

        Working...