GLPI SDK written in Python.
This SDK is written in Python to help developers integrate their apps, APIS and scripts in GLPI infrastructure. This SDK abstract the GLPI Rest API.
To usage it, you should have username, password and API-Token from your GLPI server.
To create an API token: Setup > General > API :
Enable Rest API
:Yes
See also:
Just install from:
-
PyPi:
pip install glpi
-
repository (development):
pip install -e git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi
-
requirements.txt (development)
pip install -r requirements-dev.txt
You should enable the GLPI API and generate an App Token.
Please, export these environments variables with yours config:
export username = "GLPI_USER"
export password = "GLPI_USER"
export url = 'http://glpi.example.com/apirest.php'
export glpi_app_token = "GLPI_API_TOKEN"
Then import it in your script and create a glpi
API connection:
import os
from glpi import GLPI
url = os.getenv("GLPI_API_URL") or None
user = os.getenv("GLPI_USERNAME") or None
password = os.getenv("GLPI_PASSWORD") or None
token = os.getenv("GLPI_APP_TOKEN") or None
glpi = GLPI(url, token, (user, password))
To usage the SDK, you just set the DBTM item that you want and get information from GLPI.
The Item value must be valid, otherwise you will get the following error.
[
"ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM",
"resource not found or not an instance of CommonDBTM; view documentation in your browser at http://<GLPI_URL>/apirest.php/#ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM"
]
print "Getting all Tickets: "
print json.dumps(glpi.get_all('ticket'),
indent=4,
separators=(',', ': '),
sort_keys=True)
ticket_payload = {
'name': 'New ticket from SDK',
'content': '>>>> Content of ticket created by SDK API <<<'
}
ticket_dict = glpi.create('ticket', ticket_payload)
if isinstance(ticket_dict, dict):
print "The ticket request was sent. See results: "
print json.dumps(ticket_dict,
indent=4,
separators=(',', ': '),
sort_keys=True)
print "Getting Ticket with ID 1: "
print json.dumps(glpi.get('ticket', 1),
indent=4,
separators=(',', ': '),
sort_keys=True)
print "Getting 'My' profile: "
print json.dumps(glpi.get('getMyProfiles'),
indent=4,
separators=(',', ': '),
sort_keys=True)
print "Getting 'Locations': "
print json.dumps(glpi.get('location'),
indent=4,
separators=(',', ': '),
sort_keys=True)
TODO: create an full example with various Items available in GLPI Rest API.
See CONTRIBUTING.md