Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'searchText' parameter in get_all_items api call #17

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion glpi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,21 @@ def get_item(self, itemtype, item_id, **kwargs):
404: lambda r: None
}.get(response.status_code, _unknown_error)(response)

def _add_searchtext(self, searchText):
'''
Generate searchText parameter.
'''
if not isinstance(searchText, dict):
raise GLPIError(
'search text should be a dict, found: {:s}'.format(str(type(searchText)))
)

params = {}
for key, value in searchText.items():
params.update({'searchText[{:s}]'.format(key): value})

return params
pniaps marked this conversation as resolved.
Show resolved Hide resolved

@_catch_errors
def get_all_items(self, itemtype, **kwargs):
"""`API documentation
Expand All @@ -454,9 +469,15 @@ def get_all_items(self, itemtype, **kwargs):
# Retrieve deleted computers.
>>> glpi.get_all_items('Computer', is_deleted=True)
[]
# Using searchText.
>>> glpi.get_all_items('Computer', searchText={'name':'server'})
[]
"""
params = {}
params.update(kwargs)
params.update(self._add_searchtext(kwargs.pop('searchText', {})))
response = self.session.get(self._set_method(itemtype),
params=_convert_bools(kwargs))
params=_convert_bools(params))
pniaps marked this conversation as resolved.
Show resolved Hide resolved
return {
200: lambda r: r.json(),
206: lambda r: r.json(),
Expand Down