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 2020-06-03 20:18:11

RobinDR
Member
Registered: 2020-04-17
Posts: 1

Updating fields created by 'additional fields' through the Web API.

Good evening.

I've been busy trying to integrate the GLPI Web API into my custom Python scripts. But one major hiccup I'm experiencing is attempting to update a field that was created by the additional fields plugin. This problem only occurs when updating a field that resides in a separate tab, when I try to update a field that's injected into the Computer form the API performs this task flawlessly. A quick overview of the problem:

https://<MyGlpiEnv>/apirest.php/Computer is the endpoint I use to update the item (using an HTTP PUT).

I send the following json payload to the server:

{'input': [{'id': 20, 'dellwarrantyfield': '2020-07-06'}, {'id': 20, 'assetexpirationdatefield': '2020-07-06'}]}

Which yields a 200 OK response from the server:

[{"20":true,"message":""},{"20":true,"message":""}]

However, what I notice is that 'dellwarrantyfield' (the field injected in the computer form, rather than a separate tab) is updated as I expect, but the 'assetexpirationdatefield' which resides in a different tab is not adjusted. So, I assume that the update endpoint for some reason is incapable to link the computer to the correct container created by additional fields plugin that holds the relevant information for the desired fields (this link can be established through the 'items_id' value in the respective container as far as I'm aware).
Now, the thing that kind of bothers me the most is the fact that the search endpoint is fully capable of delivering this desired behaviour. I can query the 'listSearchOptions' of the Computer object through the web API which yields the following:

76669': {'name': 'Dell Information - Dell Warranty', 'table': 'glpi_plugin_fields_computerdellinformations', 'field': 'dellwarrantyfield', 'datatype': 'date', 'nosearch': False, 'nodisplay': False, 'available_searchtypes': ['equals', 'notequals', 'lessthan', 'morethan', 'contains', 'notcontains'], 'uid': 'Computer.PluginFieldsComputerdellinformation.dellwarrantyfield'}}

'76666': {'name': 'Sofico IT - Asset expiration date', 'table': 'glpi_plugin_fields_computersoficoits', 'field': 'assetexpirationdatefield', 'datatype': 'date', 'nosearch': False, 'nodisplay': False, 'available_searchtypes': ['equals', 'notequals', 'lessthan', 'morethan', 'contains', 'notcontains'], 'uid': 'Computer.PluginFieldsComputersoficoit.assetexpirationdatefield'}

Now that I know the specific id's I can even query the information:
After some Python mumbo jumbo my script spits the following back to me:
('<MyPC>', 20, '2020-06-01', '2020-07-06'), once more showing the one value was updated as expected, whilst the other still remains. Just to be sure I can change the value of the field manually, and search again:
('<MyPC>', 20, '2020-07-06', '2020-07-06')

No problem at all. But for some reason updating does not work.

Now, I know I can also adjust an additional field through the API endpoint of that field - by using /apirest.php/PluginFieldsComputersoficoit in this case -, but for that I need the ID of the container that holds the relevant field (this works, but proves quite the workaround...). The API seems to offer no easy way to establish a connection between a computer - with id 20 for instance - and the associated record of the additional fields plugin. Unless, you would query for ALL entries and filtering on items_id = computer_id in your code, which for updating a single items seems like a very costly operation to me. Which ultimately brings me to my question, do I have a blatant oversight here, am I missing something, or is the functionality I'm describing here not part of the web API, and if so would that be part of the roadmap somewhere in the future?

Kind regards,
Robin

Offline

Board footer

Powered by FluxBB