Closed ruivit closed 8 months ago
Hello,
You don't use the update
method correctly (cf https://di.pages.unistra.fr/glpi/python-glpi-api/#glpi_api.GLPI.update). It does not take just two parameters, the second parameter being a list, but as many objects to update as parameters:
glpi.update('Computer', {'id': 1, 'name': 'test'}, {'id': 2, 'name': 'test2'})
(see this for the Python explanation)
In your exemple, the first update is incorrect and the second update will never be executed as the exception will be raised and catched by the first update.
As for trying to use requests directly, it should works (if the requests is formatted as expected by the API). I spawn a new GLPI instance with Docker (see this gist) and make some tests without errors (using iPython):
In [22]: glpi.add('Computer', {'name': 'test'})
Out[22]: [{'id': 2, 'message': 'Item successfully added: test'}]
In [23]: glpi.get_item('Computer', 2)['name']
Out[23]: 'test'
In [24]: glpi.update('Computer', {'id': 2, 'name': 'test2'})
Out[24]: [{'2': True, 'message': ''}]
In [25]: glpi.get_item('Computer', 2)['name']
Out[25]: 'test2'
In [28]: glpi.update('Computer', {'id': 1, 'name': 'test3'}, {'id': 2, 'name': 'test3'})
Out[28]: [{'1': True, 'message': ''}, {'2': True, 'message': ''}]
In [29]: glpi.get_item('Computer', 2)['name']
Out[29]: 'test3'
In [30]: glpi.add('Location', {'name': 'test'})
Out[30]: [{'id': 1, 'message': 'Item successfully added: test'}]
In [34]: glpi.update('Computer', {'id': 2, 'locations_id': 1})
Out[34]: [{'2': True, 'message': ''}]
In [35]: glpi.get_item('Computer', 2)['locations_id']
Out[35]: 1
(You cast the ids to string but the API may actually expects integers)
Hello everyone.
I can't seem to update items no matter what input I give.
I've even tried to create a request myself in which I get 200 OK but no message, nor the item is updated. `def update_location(self, computer_id, location_id): print("Updating location for computer id:", computer_id)
-d '{"input": {"id": 11, "otherserial": "abcde"}}' \
Any help will be appreciated.