added GetItems method to get any item
This commit is contained in:
35
GLPIAPI.py
35
GLPIAPI.py
@@ -102,7 +102,40 @@ class GLPIAPI:
|
|||||||
return itemID, search["data"], search["totalcount"]
|
return itemID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
|
|
||||||
|
def GetItems(self, itemType, fieldId=None, fieldValue=None):
|
||||||
|
|
||||||
|
searchAll = False
|
||||||
|
if(fieldId != None and fieldValue != None):
|
||||||
|
# Recherche en fonction de l'utilisateur de l'appareil
|
||||||
|
search_parameter = f'is_deleted=0&criteria[0][field]={fieldId}&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{fieldValue}$'
|
||||||
|
else:
|
||||||
|
searchAll = True
|
||||||
|
|
||||||
|
if(searchAll):
|
||||||
|
searchUri = f"{self.Server}/apirest.php/search/{itemType}/?range=0-9999999&is_deleted=0"
|
||||||
|
else:
|
||||||
|
searchUri = f"{self.Server}/apirest.php/search/{itemType}?{search_parameter}"
|
||||||
|
|
||||||
|
search = requests.get(searchUri, headers=self.Headers)
|
||||||
|
|
||||||
|
if(search.status_code == 200):
|
||||||
|
search = search.json()
|
||||||
|
if(search["totalcount"] == 1):
|
||||||
|
itemID = list(search["data"].keys())[0]
|
||||||
|
data = search["data"][itemID]
|
||||||
|
|
||||||
|
return itemID, data, search["totalcount"]
|
||||||
|
elif(search["totalcount"] > 1):
|
||||||
|
if(searchAll):
|
||||||
|
# return None since id can be in a different key based on itemtype
|
||||||
|
itemID = None
|
||||||
|
else:
|
||||||
|
itemID = list(search["data"].keys())
|
||||||
|
return itemID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
|
return None, None, 0
|
||||||
|
|
||||||
def GetUsers(self, username=None, email=None):
|
def GetUsers(self, username=None, email=None):
|
||||||
'''
|
'''
|
||||||
Search for users in GLPI based on one of the possibles parameters :
|
Search for users in GLPI based on one of the possibles parameters :
|
||||||
@@ -141,7 +174,7 @@ class GLPIAPI:
|
|||||||
return userID, search["data"], search["totalcount"]
|
return userID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
|
|
||||||
def UploadFile(self, file, path):
|
def UploadFile(self, file, path):
|
||||||
manifest = {
|
manifest = {
|
||||||
"input": {
|
"input": {
|
||||||
|
|||||||
Reference in New Issue
Block a user