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

    Manage tags using API

    Scheduled Pinned Locked Moved General
    3 Posts 2 Posters 474 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
      fa__
      last edited by

      Hello,

      I'm testing the use of tags. I have created a different topic to ask about the purpose of tags but I believe it is worthy to ask separately about the use of tags through the API.

      As tags are attributes of the General category, I would expect to retrieve tags using cmdb.object.read. However, it is not the case. I would also expect to be able to assign tags to an object using cmdb.object.create. It hasn't worked for me either.

      I have considered that the issue may be related to the fact that tags is a multiselect attribute. So, I have checked another multiselect attribute (fiber_wave_lengths of category Cabling-> Connectors). The values can be retrieved as expected with cmdb.category.read but title-based creation is not allowed and the only way I have found to retrieve the id of the possible values for the attribute is to read them from an object where it has previously been manually assigned. This is not convenient.

      Questions:

      • Is it possible to work with tags using the API? What am I doing wrong?

      • Is it possible to retrieve the list of values that can be assigned to a multiselect attribute?

      My attempts:

      1. I have created an object in the i-doit demo and manually assigned a tag
        0edb9c30-52d6-4303-90d7-269e2e5fcbe8-imagen.png

      2. Trying to read the tags with cmdb.object.read:

          {
             "version": "2.0",
             "method": "cmdb.object.read",
             "params": {
                 "objID": 5385,
                 "apikey": "c1ia5q",
                 "language": "en"
              },
            "id": 1
         }
        
        {
            "id": 1,
            "jsonrpc": "2.0",
            "result": {
                "id": 5385,
                "title": "Host 1",
                "sysid": "CLOUD_0005385",
                "objecttype": 39,
                "type_title": "Host",
                "type_icon": "images/icons/silk/server.png",
                "status": 2,
                "cmdb_status": 6,
                "cmdb_status_title": "in operation",
                "created": "2021-06-17 09:51:47",
                "updated": "2021-06-17 09:52:47",
                "image": "https://demo.i-doit.com/images/objecttypes/server.png"
            }
        }
        
      3. Trying to create an object with an existing tag.

        {
           "version": "2.0",
           "method": "cmdb.object.create",
           "params": {
                "type": "C__OBJTYPE__HOST",
                "title": "Host 2",
                "tag": "asdasd", 
                "apikey": "c1ia5q",
                "language": "en"
            },
            "id": 1
        }
        
        
        {
            "id": 1,
            "jsonrpc": "2.0",
            "result": {
                "id": 5391,
                "message": "Object was successfully created",
                "success": true
            }
        }
        
      4. Checking the object created in the web
        b0231ac1-e8fc-4b1c-aeaf-30ea8ecb4374-imagen.png

      Michael HuhnM 1 Reply Last reply Reply Quote 0
      • Michael HuhnM Offline
        Michael Huhn @fa__
        last edited by

        Hello @fa__,

        first, Tags are a Dialog+ Multi-Dialog field.
        You can edit them via cmdb.dialog, see here -> https://kb.i-doit.com/display/en/Methods#Methods-cmdb.dialog.read

        Tags belong to the Category General, so you can check how to edit this category via the API categories and attributes
        e2fbd0e5-44e3-4380-b5a4-d5efb2ebf6af-image.png

        Here is a example:

        {
        	"method": "cmdb.category.save",
        	"params": {
        		"object": 1122546692,
        		"category": "C__CATG__GLOBAL",
        		"data": {
        			"tag": [
        				"Tag1",
        				"Tag2",
        				"Tag3"
        			]
        		},
        		"apikey": "apikey"
        	},
        	"id": 3,
        	"version": "2.0"
        }
        

        If you cant to create a object with Tags you need to do it this way:

        {
        	"id": 1,
        	"version": "2.0",
        	"method": "cmdb.object.create",
        	"params": {
        		"type": "C__OBJTYPE__SERVER",
        		"title": "MyLittleServer",
        		"categories": {
        			"C__CATG__GLOBAL": [
        				{
        					"tag": [
        						"Tag1",
        						"Tag2",
        						"Tag3"
        					]
        				}
        			],
        			"C__CATG__MODEL": [
        				{
        					"serial": "1337ÜÄÖ"
        				}
        			]
        		},
        		"apikey": "apikey",
        		"language": "en"
        	}
        }
        
        F 1 Reply Last reply Reply Quote 1
        • F Offline
          fa__ @Michael Huhn
          last edited by

          Thanks @michael-overkamp!

          I had not undestood that multiselect is a Dialog+, I thought it was a different kind of attribute.

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