You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2025-02-18 11:30:35

Hecatte
Member
Registered: 2024-05-23
Posts: 2

[Resolved] Update computer tags with API

Hi everyone,

We use GLPI to monitor our computers fleet and would like to use the API to update some fields, especially the 'Tags' field provided by the Tags plugin.
We are already aware that dropdown fields have a specific behaviour and we already manage most of them, but I can't figure out how to manage a multiple choice dropdown field, like Tags seems to be.

This is the Tags field information provided by calling the API at /listSearchOptions/Computer:

	"10500": {
		"name": "Etiquettes",
		"table": "glpi_plugin_tag_tags",
		"field": "name",
		"datatype": "dropdown",
		"nosearch": false,
		"nodisplay": false,
		"available_searchtypes": [
			"equals",
			"notequals",
			"contains",
			"notcontains"
		],
		"uid": "Computer.PluginTagTagItem.PluginTagTag.name"
	},

And this is the --data json passed to my PUT requests I've already tried so far (without success):

{
	"input": {
		"plugin_tag_tags_id": "1"
	}
}

{
	"input": {
		"plugin_tag_tags_id": ["1"]
	}
}

{
	"input": {
		"plugin_tag_tags_id": "mytag"
	}
}

{
	"input": {
		"plugin_tag_tags_id": ["mytag"]
	}
}

(I'm requesting the API at /Computer/<id>)

I'm running out of ideas...

Thank you by advance,

Agathe

Last edited by Hecatte (2025-02-20 15:29:03)

Offline

#2 2025-02-18 13:03:02

cconard96
Moderator
Registered: 2018-07-31
Posts: 3,288
Website

Re: [Resolved] Update computer tags with API

The current API is a bit confusing but I'll try to explain.

The current API is very low level. There is only a little bit of code between the API requests and the actual internal code we use to search/fetch/update items in GLPI. The search options only affect the search endpoints as they are used to generate the SQL required. When you get a specific item, list items, create items, or update items, you are working directly with the "fields" data in the items.

For tags, "plugin_tag_tags_id" doesn't exist in the Computer table, so you cannot change it like that. The item types for the data in the Tags plugin are "PluginTagTag" which are the actual tag definitions, and "PluginTagTagItem" which are the links between items and tags.


Knowing that the current API is very complex, we started work on a new API that will be released in the next major version of GLPI (version 11.0) which is more abstract and lets us map data better and present it in a more user friendly way. Since it isn't just a wrapper around the internal code, it won't "just work" for everything as each type of item like Computers needs to have its support explicitly added, but it will be a lot easier to get started with. It will even launch with some interesting features like GraphQL support and the ability to return some data as a CSV or XML instead of just JSON.

You can see more information about the new API in the initial PR for it here:
https://github.com/glpi-project/glpi/pull/12221

You can also see that I started work on the support for this new API in the tag plugin here:
https://github.com/pluginsGLPI/tag/pull/139

The current API will not be removed but we will be strongly recommending the use of the new API whenever possible.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2025-02-20 15:27:01

Hecatte
Member
Registered: 2024-05-23
Posts: 2

Re: [Resolved] Update computer tags with API

Thank you for your answer ! I've been able to write some code to update tags thanks to the item type you gave me, awaiting the GLPI 11.0 release smile

Have a nice day

Offline

Board footer

Powered by FluxBB