4 Commits

Author SHA1 Message Date
6f3434e8db Updated build number and gitea workflow
Some checks failed
Build python package / Build (push) Failing after 19s
2026-03-28 19:25:59 +01:00
0155644b65 Updated GetItems method to use GetSearchOptions method to find fields id 2026-03-28 19:15:43 +01:00
3d920fd5e5 added a method to get search options for items 2026-03-28 18:15:14 +01:00
660b8e8463 added GetItems method to get any item 2026-03-28 17:41:15 +01:00
3 changed files with 60 additions and 4 deletions

View File

@@ -4,13 +4,15 @@ on: [push]
jobs: jobs:
Build: Build:
runs-on: windows runs-on: ubuntu-latest
container:
image: python
steps: steps:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@main uses: actions/checkout@main
- name: Building the package - name: Building the package
run: | run: |
powershell mv ${{ gitea.workspace }}\GLPIAPI.py ${{ gitea.workspace }}\build\src\GLPIAPI\ mv ${{ gitea.workspace }}\GLPIAPI.py ${{ gitea.workspace }}\build\src\GLPIAPI\
cd ${{ gitea.workspace }}\build cd ${{ gitea.workspace }}\build
python -m build python -m build
- name: Publish package - name: Publish package

View File

@@ -103,6 +103,48 @@ class GLPIAPI:
return None, None, 0 return None, None, 0
def GetItems(self, itemType, fieldName=None, fieldValue=None):
'''
Search for items of a specific item type in GLPI. A filter can be set using fieldName and fieldValue :
fieldName: must be the name of the field as visible in GLPI
fieldValue: a string
If only itemType is set, it will search for all items
Return a tuple with item id (in a list if there are more than 1), item data (in a list of dict items) and item count (int).
If the query does not succeed it will return a tuple with the http status code instead of item data (e.g. None, 400, 0).
'''
searchAll = False
if(fieldName != None and fieldValue != None):
fieldId = list(self.GetSearchOptions(itemType, fieldName))[0]
# 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):
idFieldNumber = list(self.GetSearchOptions(itemType, 'id'))[0]
itemID = [i[idFieldNumber] for i in search["data"]]
else:
itemID = list(search["data"].keys())
return itemID, search["data"], search["totalcount"]
return None, search.status, 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 :
@@ -142,6 +184,18 @@ class GLPIAPI:
return None, None, 0 return None, None, 0
def GetSearchOptions(self, itemType, fieldName=None):
queryUri = f"{self.Server}/apirest.php/listSearchOptions/{itemType}"
searchOptions = requests.get(queryUri, headers=self.Headers)
if(searchOptions.status_code == 200):
searchOptions = searchOptions.json()
if(fieldName != None):
for k,v in searchOptions.items():
if(v['name'].lower() == fieldName.lower()):
return {k : searchOptions[k]}
return searchOptions
return searchOptions.status_code
def UploadFile(self, file, path): def UploadFile(self, file, path):
manifest = { manifest = {
"input": { "input": {

View File

@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "GLPIAPI" name = "GLPIAPI"
version = "1.0.3" version = "1.0.4"
description = "A module python to make it easier to use GLPI API" description = "A module python to make it easier to use GLPI API"
readme = "README.md" readme = "README.md"
dependencies = [ dependencies = [