From c780c305335ab8153676f633f2c14780c0d3e292 Mon Sep 17 00:00:00 2001 From: Jason SECULA Date: Fri, 27 Feb 2026 08:07:48 +0100 Subject: [PATCH] added SetField for normal fields and SetCustomField for custom fields --- GLPIAPI.py | 21 ++++++++++++++++++++- build/pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/GLPIAPI.py b/GLPIAPI.py index 633e141..01320cf 100644 --- a/GLPIAPI.py +++ b/GLPIAPI.py @@ -127,7 +127,26 @@ class GLPIAPI: "user-agent":self.UserAgent } return requests.post(self.Server, headers=headers, data=inventory) + + def SetField(self, itemType, itemId, data): + '''Modify fields of a GLPI item. + Input must be a dict formatted like this : + { + "fieldName1": "fieldValue1", + "fieldName2": "fieldValue2", + ... + } + ''' + body = { + "input" : { + "id" : itemId, + } + } + body["input"] = {**body["input"], **data} + uri = f"{self.Server}/apirest.php/{itemType}/" + return requests.put(uri, headers=self.Headers, json=body) + def UpdateSerialNumber(self, deviceid, serialnumber): body = { @@ -150,7 +169,7 @@ class GLPIAPI: uri = f"{self.Server}/apirest.php/Computer/" return requests.put(uri, headers=self.Headers, json=body) - def SetField(self, itemType, containerName, containerID, itemId, fieldName, data): + def SetCustomField(self, itemType, containerName, containerID, itemId, fieldName, data): '''Requires fields plugin on GLPI server - containerName is block label name - containerID is block id diff --git a/build/pyproject.toml b/build/pyproject.toml index 2c2ca1b..50b1fba 100644 --- a/build/pyproject.toml +++ b/build/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "GLPIAPI" -version = "1.0.1" +version = "1.0.2" description = "A module python to make it easier to use GLPI API" readme = "README.md" requires-python = ">=3.7"