PHP code example of glpi-project / php-library-glpi
1. Go to this page and download the library: Download glpi-project/php-library-glpi library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
glpi-project / php-library-glpi example snippets
// Instanciate the API client
$client = new Glpi\Api\Rest\Client('http://localhost/glpi/apirest.php/', new GuzzleHttp\Client());
// Authenticate
try {
$client->initSessionByCredentials('glpi', 'glpi');
} catch (Exception $e) {
echo $e->getMessage();
die();
}
// The client handles the session token for you (app token not yet supported)
// do something
$itemHandler = new \Glpi\Api\Rest\ItemHandler($client);
$response = $itemHandler->getItem('User', 2);
$user = json_decode($response['body']);
echo "User name: " . $user->name . "\n";