Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(example): added example of use
Browse files Browse the repository at this point in the history
  • Loading branch information
DIOHz0r authored and ajsb85 committed Oct 25, 2017
1 parent 88ec8f4 commit 642b047
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions example/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* LICENSE
*
* Copyright © 2017 Teclib'
*
* This file is part of GLPI Api Client Library for PHP.
*
* GLPI Api Client Library for PHP is a subproject of Flyve MDM. Flyve MDM is a mobile
* device management software.
*
* GLPI Api Client Library for PHP is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* GLPI Api Client Library for PHP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with GLPI Api Client Library for PHP. If not, see http://www.gnu.org/licenses/.
* ------------------------------------------------------------------------------
* @author Domingo Oropeza
* @copyright Copyright © 2017 Teclib
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
* @link https://github.com/flyve-mdm/composer-package-glpi
* @link https://flyve-mdm.com/
* ------------------------------------------------------------------------------
*/

require_once __DIR__ . '/../vendor/autoload.php';

$client = new \Glpi\Api\Rest\Client('http://localhost/glpi/apirest.php/');

try {
// try to do login
$client->initSessionByCredentials('glpi', 'glpi');
} catch (Exception $e) {
// print the error if failed
echo $e->getMessage();
die();
}

// Let's make a request to an End Point
$endPointHandler = new \Glpi\Api\Rest\EndPointHandler($client);
$response = $endPointHandler->getMyProfiles();
$profiles = json_decode($response['body']);
foreach ($profiles->myprofiles as $profile) {
echo "Profile name: " . $profile->name . "\n";
}

// Let's work with item types
$itemHandler = new \Glpi\Api\Rest\ItemHandler($client);
$response = $itemHandler->getAnItem('User', 2);
$bodyDecoded = json_decode($response['body']);
if ($response['statusCode'] == 404) {
// User not found
die($bodyDecoded[1]);
}
echo "User name: " . $bodyDecoded->name . "\n";

// let's end the session.
$client->killSession();

0 comments on commit 642b047

Please sign in to comment.