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

    Update a single-value category with Api

    Scheduled Pinned Locked Moved Development
    8 Posts 2 Posters 1.2k Views
    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.
    • M Offline
      mirkomatonti
      last edited by

      Hi,
      I'm trying to update the value of the Operating System category(C__CATG__OPERATING_SYSTEM) using json api.

      This is the request:

      {
        "version": "2.0",
        "method": "cmdb.category.update",
        "params": {
          "category": "C__CATG__OPERATING_SYSTEM",
          "objID": 6531,
          "data": {
            "application": 5771,
            "assigned_version": 9
          },
          "apikey": "******",
          "language": "en"
        },
        "id": "1"
      }
      

      Response from the db:

      {
        "id": "1",
        "jsonrpc": "2.0",
        "error": {
          "code": -32603,
          "message": "Internal error: Validation errors in dialog related properties occured.",
          "data": {
            "assigned_version": "(dialog_plus) Id value(s) '9' do not exist in dialog table. Please check your provided selection."
          }
        }
      }
      

      I'm sure the value '9' mentioned in the error message exist. The problem only appears when updating, If I purge the category, then I can recreate it with the same data.

      1 Reply Last reply Reply Quote 0
      • Philipp HörselmannP Offline
        Philipp Hörselmann
        last edited by

        Hi @mirkomatonti
        does the entry for "assigned_version" is the entry-id or the value in the i-doit gui?
        If 9 is the value which can be selected in the dropdown menu in the gui, you need to write it with quotation marks for the api request
        Extract:

        "data": {
              "application": 5771,
              "assigned_version": "9"       <----------
            },
        

        Furthermore, the update method is deprecated and I recommend to use the save method.
        in your case this would looks like the following snippet:

        {
        	"jsonrpc": "2.0",
        	"method": "cmdb.category.save",
        	"params": {
        		"category": "C__CATG__OPERATING_SYSTEM",
        		"apikey": "*********",
                        "language": en
        		"object": 6531,
        		"data": {
        			"application": 5771,
        			"assigned_version": "9"
        		}
        	},
        	"id": 1
        }
        

        Cheers,
        Phil

        M 1 Reply Last reply Reply Quote 1
        • M Offline
          mirkomatonti @Philipp Hörselmann
          last edited by

          Hi @Philipp-Hörselmann , thank you, changing to "value" it worked!

          Now I have the same problem updating the "C__CATG__VIRTUAL_MACHINE".
          If I run this on a new object everything goes fine:

          {
            "version": "2.0",
            "method": "cmdb.category.save",
            "params": {
              "category": "C__CATG__VIRTUAL_MACHINE",
              "object": 6600,
              "data": {
                "virtual_machine": 2,
                "hosts": 834,
                "primary": 6597,
                "system": 10
              },
              "apikey": "******",
              "language": "en"
            },
            "id": "1"
          }
          

          Let's say I want to change the "Running on host"' and the "Host in cluster" properties to (253,6444) respectively:

          {
           "version": "2.0",
           "method": "cmdb.category.save",
           "params": {
             "category": "C__CATG__VIRTUAL_MACHINE",
             "object": 6600,
             "data": {
               "virtual_machine": 2,
               "hosts": 253,
               "primary": 6444,
               "system": 10
             },
             "apikey": "******",
             "language": "en"
           },
           "id": "1"
          }
          

          Same error:

          {
            "primary": "(dialog) Id value(s) '6444' do not exist in dialog table. Please check your provided selection."
          }
          

          The problem shows up only with the api, on the web GUI I can change them manually and if I do a category.read I get the correct updated values (hosts:253,primary:6444):

          {
            "id": "1",
            "jsonrpc": "2.0",
            "result": [
              {
                "id": "290",
                "objID": "6600",
                "virtual_machine": {
                  "id": "2",
                  "title": "Yes",
                  "const": "",
                  "title_lang": "LC__UNIVERSAL__YES"
                },
                "hosts": {
                  "title": "Test Cluster",
                  "id": "253",
                  "connection_id": "2981",
                  "type": "C__OBJTYPE__CLUSTER",
                  "type_title": "Cluster",
                  "sysid": "SYSID_1583768396"
                },
                "system": {
                  "id": "10",
                  "title": "XEN",
                  "const": null,
                  "title_lang": "XEN"
                },
                "config_file": "",
                "primary": {
                  "id": "6444",
                  "title": "Test Server",
                  "sysid": "SYSID_1589213521",
                  "type": "C__OBJTYPE__SERVER",
                  "type_title": "Server"
                },
                "description": ""
              }
            ]
          }
          

          Sorry for the long post, I hope the explanation of the problem is clear.
          Thanks for the help.

          Best,
          Mirko

          1 Reply Last reply Reply Quote 0
          • Philipp HörselmannP Offline
            Philipp Hörselmann
            last edited by

            Hey @mirkomatonti
            what versions of i-doit and the APIU add-on are you using?
            I cannot reproduce this on i-doit 1.14.2 with the API add-on 1.11.1.

            Cheers,
            Phil

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              mirkomatonti @Philipp Hörselmann
              last edited by

              @Philipp-Hörselmann

              I-doit 1.14 and api version1.10.4

              Best,
              Mirko

              1 Reply Last reply Reply Quote 0
              • Philipp HörselmannP Offline
                Philipp Hörselmann
                last edited by

                Hi @mirkomatonti
                that's a bug which was fixed with the latest version of the API (1.11.1) 😉
                I recommend to update both to the actual versions.

                Cheers,
                Phil

                M 1 Reply Last reply Reply Quote 1
                • M Offline
                  mirkomatonti @Philipp Hörselmann
                  last edited by

                  @Philipp-Hörselmann
                  Great 🙂 Do you know where I can find the API(1.11.1)?

                  Best,
                  Mirko

                  1 Reply Last reply Reply Quote 0
                  • Philipp HörselmannP Offline
                    Philipp Hörselmann
                    last edited by

                    Hi @mirkomatonti
                    do you use the i-doit open or i-doit pro?
                    If you are using the open version you can find the download in the download section of https://www.i-doit.org/download/
                    If you are using the pro version you can download the version from the customer portal with your customer login 😉
                    Cheers,
                    Phil

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