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.
    • 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
                  • F Offline
                    FlatErik @FlatErik
                    last edited by

                    @LFischer @Kleinrotti Has anyone please an answer?

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

                      Hello @FlatErik

                      I'm afraid you can not "unselect" the relationship category inside the templates, since they will always take the complete object "as-is" and replicate it or use it as mass-change basis.

                      Usually (with any other category) I would say you can simply "clear" all entries from the category you don't want, but that won't work for the relationship category unless you remove all entries that created any implicit relations 😕

                      I have not red every post here - could you sum up what's the problem?

                      Best regards
                      Leo

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        mamawe @mamawe
                        last edited by

                        @mamawe said in API create object from template:

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

                        Just tested with API version 1.13.1: it works there too, but has to be inserted at line 292.

                        Kind regards,
                        Mathias

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