Community
    • Categories
    • Recent
    • Popular
    • Users
    • Search
    • Register
    • Login

    Get all object data via API

    Scheduled Pinned Locked Moved Development
    7 Posts 5 Posters 2.9k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      beerygaz
      last edited by

      Is there an example somewhere to return all of the data from an object? I see the CLI and PHP API wrappers have a "load" method that does this, but it would be nice to have an example of how?

      Alternatively how do I request just the data for one or two specific categories attached to an object (Contact info, or custom attributes for example).

      Also, is there an English version of this document please:
      https://kb.i-doit.com/download/attachments/37355644/i-doit JSON-RPC 1.8.3.pdf?version=1&modificationDate=1489677685764&api=v2

      1 Reply Last reply Reply Quote 0
      • bheisigB Offline
        bheisig i-doit Team
        last edited by

        Hi,

        Sorry for the late answer.

        To "load" everything about an object:

        1. Fetch common information about an object by cmdb.object.read or cmdb.objects.read. Now you know its object type.
        2. Fetch all relevant categories for this object by cmdb.object_type_categories.read. Now you know all category constants.
        3. Read all attributes from every category with a batch request. For every category use cmdb.category.read.

        Within 3 API requests you know has every detail about an object.

        In a future release we will enhance the API so only 1 request is needed.

        At the moment, we are migrating the out-dated PDF documentation to this KB article. I hope it helps.

        Greetings,
        Ben

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          ahrensde
          last edited by

          I already figured out step one and two. But I stumble upon the third one.

          Is there a way to receive all category related data for an object in one API request? Currently I need to do ~30 requests per object (because there are that many categories attached to it) which performs quite poor when fetching 400 records.

          12000 HTTP requests for reading the data related to 400 objects is a lot IMO. Is there something I am missing or is this currently not supported? (i-doit 1.11)

          1 Reply Last reply Reply Quote 0
          • bheisigB Offline
            bheisig i-doit Team
            last edited by

            Hi,

            you definitely should use batch requests to reduce API requests significantly. Put the 30 cmdb.category.read requests for an object into one batch request. That means for 400 objects you only need 400 batch requests instead of 12.000.

            In most cases you can combine the 30 cmdb.category.read requests for more than one object into only one batch request. On a fast¹ i-doit host you may put up to ~ 600 requests into one batch request – maybe even more:

            400 objects x 30 categories / 600 requests per batch request = 20 batch requests

            Happy coding
            — Benjamin

            ¹ for example, fast DB with a lot of i/o (flash memory or everything loaded into ram), 1-2 gigs of RAM for each PHP process

            1 Reply Last reply Reply Quote 0
            • A Offline
              ahrensde
              last edited by ahrensde

              Thank you for the reply! This sounds much better 🙂

              While I wanted to ask again about this batch requests, I did some additionaly research...

              The only mentioning of batch request that I found in the i-doit documentation is in the "Tips and Tricks" section - the API documentation (1, 2, 3, 4) does not contain a single word.

              There is the JSON RPC 2.0 documentation, which specifies it - but the outdated PDF documentation tells me that batch is not supported.

              EDIT: ok, outdated docs tell that batch requests are supported since 1.4...

              Would be cool to get more information on that topic directly in the docs - because if you really want to do something useful with your API IMO this information is absolutely required. Otherwise you'll waste a lot of time with HTTP requests. And JSON RPC 2.0 is not that well known, that you can assume everybody knows that before. It is neither SOAP nor REST 😉

              Nevertheless - thanks for pointing me in the proper direction! I'll try this now.

              1 Reply Last reply Reply Quote 1
              • A Offline
                arthur.koch @bheisig
                last edited by

                @bheisig

                Is the the function to get all categories and it's contents of an object already implemented?

                U 1 Reply Last reply Reply Quote 0
                • U Offline
                  uhe @arthur.koch
                  last edited by

                  @arthur-koch
                  yes it is, but afaik there is no documentation.
                  In python looks somehow like this:

                  data = {
                      'id': 1,
                      'version': '2.0',
                      'method': 'cmdb.object_type_categories.read',
                      'params': {
                          'apikey': self.apikey,
                          'language': self.language,
                          'type': obj_id 
                      },
                  }
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post