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

    API create object from template

    Scheduled Pinned Locked Moved Development
    26 Posts 5 Posters 3.2k Views 1 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.
    • LFischerL Offline
      LFischer @Kleinrotti
      last edited by

      Hey @kleinrotti

      the error message comes from the internal validation, but sadly it does not mention which category or attribute are responsible πŸ˜• This might prevent one (or more) categories from being created.
      I'll note this down as a bug - the error message should be part of the API response.

      Could you check your validation and if the object does (aside from the affected category) match your default profile?

      KleinrottiK 1 Reply Last reply Reply Quote 0
      • KleinrottiK Offline
        Kleinrotti @LFischer
        last edited by

        @lfischer The only validation we have is, that the object title needs to be unique. I have tried several object types like Printer, Monitor, Client but I get this error with all them. I tried different templates which I set as default but no chance. Every time the object is created, but none of the categories, no matter which template is set as default, are applied.

        Here is a screenshot from our validation settings.
        e904695c-f4e5-4e3e-84de-76c401d105b8-image.png

        LFischerL 1 Reply Last reply Reply Quote 0
        • LFischerL Offline
          LFischer @Kleinrotti
          last edited by

          Hey @kleinrotti

          that's interesting - but I believe we should be able to reproduce this issue very easily. Are you using any placeholders in your object title (either the default template and the object you try to create)?

          I will adjust the bug I previously created... I'm afraid I have no "work around" up my sleeve, so you might need to wait for a new API version.

          I'll also create a feature request regarding "create object from template" πŸ™‚

          KleinrottiK 1 Reply Last reply Reply Quote 0
          • KleinrottiK Offline
            Kleinrotti @LFischer
            last edited by

            @lfischer No I don't use placeholders in titles of the objects/templates.
            For testing purposes I disabled the validation/unique setting for the title and it's working this way - no error. But I need this settings for production, so I have to enable it again.
            This bug definitely has something to do with the validation setting.
            I would really appreciate if that bug could be fixed and if that feature request would be implemented.

            1 Reply Last reply Reply Quote 0
            • KleinrottiK Offline
              Kleinrotti
              last edited by

              @LFischer Are there already any news when a bugfix will be released?

              LFischerL 1 Reply Last reply Reply Quote 0
              • LFischerL Offline
                LFischer @Kleinrotti
                last edited by

                Hey @kleinrotti

                sadly I have no updates yet, currently we are working on the i-doit 1.17.2 version which is going to be released shortly.
                I believe after that we will check the API add-on πŸ™‚

                Best regards

                1 Reply Last reply Reply Quote 0
                • KleinrottiK Offline
                  Kleinrotti
                  last edited by

                  Hey @LFischer
                  are there any new information?

                  LFischerL 1 Reply Last reply Reply Quote 0
                  • LFischerL Offline
                    LFischer @Kleinrotti
                    last edited by

                    Hi @kleinrotti ,

                    I'm afraid I have no new information for you 😞 Right now the team is working on the upcoming i-doit 1.18 version. There will also be a API release around that time, but it will not contain this feature.

                    Best regards

                    KleinrottiK 1 Reply Last reply Reply Quote 0
                    • KleinrottiK Offline
                      Kleinrotti @LFischer
                      last edited by

                      @lfischer
                      And what about the bugfix for the default template? Even that would help me πŸ™‚

                      LFischerL 1 Reply Last reply Reply Quote 0
                      • LFischerL Offline
                        LFischer @Kleinrotti
                        last edited by

                        Hey @kleinrotti

                        again - sadly no updates regarding this topic 😞

                        1 Reply Last reply Reply Quote 0
                        • KleinrottiK Offline
                          Kleinrotti
                          last edited by

                          It's quite a while now but are there new information to this topic?
                          Unfortunately our workflow is not that good due to this bug. Every time we want to mass import ordered products from delivery notes with a tool, we have to disable the validation with a user which has the appropriate rights in i-doit. Afterwards we have to enable it again. This causes loss in time or if someone forgets to disable the validation, the products are not imported correctly and it has to be repeated.
                          Or is there a possibility to provide a pull request for the official API-Addon to provide a bug fix myself?

                          1 Reply Last reply Reply Quote 0
                          • L Offline
                            leobaer
                            last edited by

                            Hi
                            Did you check
                            system settings > Tenantsettings > Unique checks > object title
                            But I don't know if this is only valid for the Extras > import mechanism or for API as well.

                            Du you really need global unique titles in your daily processes? Maybe "Unique (per Object type)" is sufficient (but not sure if this triggers the bug or not)

                            Regards
                            Leo

                            KleinrottiK 1 Reply Last reply Reply Quote 0
                            • KleinrottiK Offline
                              Kleinrotti @leobaer
                              last edited by

                              @leobaer Sorry for my late reply. Your idea to change the global unique setting to "Unique per Object type" worked. Using this setting works without the error. Thanks for that πŸ™‚

                              I was also able to implement the feature to use templates in the API Addon by my self. Happily this was just a few lines of code.

                              F 1 Reply Last reply Reply Quote 0
                              • F Offline
                                FlatErik @Kleinrotti
                                last edited by

                                @Kleinrotti
                                Hi Kleinrotti,

                                We are also looking for a solution to create a new object from a template using the API. Could you explain what exactly you implemented in the API addon to make it work?

                                Grüße!

                                Erik

                                KleinrottiK 1 Reply Last reply Reply Quote 0
                                • KleinrottiK Offline
                                  Kleinrotti @FlatErik
                                  last edited by

                                  @FlatErik I added these lines of code to the file isys_api_model_cmdb_object.class.php at line 262 of the API Addon (Version 1.12.3).

                                  if (isset($p_params['useTemplate']) && $p_params['useTemplate']) {
                                                      // Get template module.
                                                      $l_template_module = new isys_module_templates();
                                  
                                                      $l_template_module->create_from_template(
                                                          [$p_params['useTemplate']],
                                                          $p_params['type'],
                                                          $p_params['title'],
                                                          $l_return['id'],
                                                          false,
                                                          1,
                                                          '',
                                                          $p_params['category'],
                                                          $p_params['purpose']
                                                      );
                                                  }
                                  

                                  Sample API Request:

                                  {
                                      "version": "2.0",
                                      "id": "1",
                                      "method": "cmdb.object.create",
                                      "params": {
                                          "apikey": "xyz",
                                          "language": "de",
                                          "type": "C__OBJTYPE__CLIENT",
                                          "title": "CLIENT-TEMP-638001685961295254",
                                          "purpose": null,
                                          "cmdb_status": 0,
                                          "description": null,
                                          "category": null,
                                          "useTemplate": 583
                                      }
                                  

                                  useTemplate provides the Id of the template.

                                  M F 2 Replies Last reply Reply Quote 0
                                  • M Offline
                                    mamawe @Kleinrotti
                                    last edited by

                                    @Kleinrotti I can confirm that this works with API version 1.13 too.

                                    Thanks a lot, this saves some API calls when importing a few hundred switches and makes the scripts easier to write.

                                    Kind regards,
                                    Mathias

                                    M 1 Reply Last reply Reply Quote 0
                                    • F Offline
                                      FlatErik @Kleinrotti
                                      last edited by

                                      Hey @Kleinrotti, Hey @mamawe !

                                      could someone please tell us, where do we find the template id?
                                      We tried the whole thing with the object id of the template.. but i didnt work.

                                      Regrads
                                      Erik

                                      KleinrottiK 1 Reply Last reply Reply Quote 0
                                      • KleinrottiK Offline
                                        Kleinrotti @FlatErik
                                        last edited by

                                        @FlatErik ab5d0770-de5c-4e93-a668-2c6df7f5d66d-image.png

                                        F 1 Reply Last reply Reply Quote 1
                                        • F Offline
                                          FlatErik @Kleinrotti
                                          last edited by

                                          Hey @Kleinrotti

                                          it worked out. Thank you!
                                          We still have the problem, that we want to create the new object without using all globel categories..
                                          Do you know if it's possible to create the new object from a template without using the Relationship Category?
                                          The Duplicat-Function allows you to unselect the unwanted categories..

                                          Anmerkung 2022-11-07 173503.jpg

                                          F 1 Reply Last reply Reply Quote 0
                                          • F Offline
                                            FlatErik @FlatErik
                                            last edited by

                                            @FlatErik @LFischer @Kleinrotti

                                            I can't find any indication in the documentation that the duplicate-function can be used via the API. Is that right?

                                            F 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post