-
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:
-
I have created an object in the i-doit demo and manually assigned a tag
-
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" } }
-
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 } }
-
Checking the object created in the web
-
-
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.readTags belong to the Category General, so you can check how to edit this category via the API categories and attributes
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" } }
-
Thanks @michael-overkamp!
I had not undestood that multiselect is a Dialog+, I thought it was a different kind of attribute.