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

Commit 642b047

Browse files
DIOHz0rajsb85
authored andcommitted
feat(example): added example of use
1 parent 88ec8f4 commit 642b047

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

example/example.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* LICENSE
4+
*
5+
* Copyright © 2017 Teclib'
6+
*
7+
* This file is part of GLPI Api Client Library for PHP.
8+
*
9+
* GLPI Api Client Library for PHP is a subproject of Flyve MDM. Flyve MDM is a mobile
10+
* device management software.
11+
*
12+
* GLPI Api Client Library for PHP is free software: you can redistribute it and/or
13+
* modify it under the terms of the GNU Affero General Public License as published
14+
* by the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
* GLPI Api Client Library for PHP is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with GLPI Api Client Library for PHP. If not, see http://www.gnu.org/licenses/.
22+
* ------------------------------------------------------------------------------
23+
* @author Domingo Oropeza
24+
* @copyright Copyright © 2017 Teclib
25+
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
26+
* @link https://github.com/flyve-mdm/composer-package-glpi
27+
* @link https://flyve-mdm.com/
28+
* ------------------------------------------------------------------------------
29+
*/
30+
31+
require_once __DIR__ . '/../vendor/autoload.php';
32+
33+
$client = new \Glpi\Api\Rest\Client('http://localhost/glpi/apirest.php/');
34+
35+
try {
36+
// try to do login
37+
$client->initSessionByCredentials('glpi', 'glpi');
38+
} catch (Exception $e) {
39+
// print the error if failed
40+
echo $e->getMessage();
41+
die();
42+
}
43+
44+
// Let's make a request to an End Point
45+
$endPointHandler = new \Glpi\Api\Rest\EndPointHandler($client);
46+
$response = $endPointHandler->getMyProfiles();
47+
$profiles = json_decode($response['body']);
48+
foreach ($profiles->myprofiles as $profile) {
49+
echo "Profile name: " . $profile->name . "\n";
50+
}
51+
52+
// Let's work with item types
53+
$itemHandler = new \Glpi\Api\Rest\ItemHandler($client);
54+
$response = $itemHandler->getAnItem('User', 2);
55+
$bodyDecoded = json_decode($response['body']);
56+
if ($response['statusCode'] == 404) {
57+
// User not found
58+
die($bodyDecoded[1]);
59+
}
60+
echo "User name: " . $bodyDecoded->name . "\n";
61+
62+
// let's end the session.
63+
$client->killSession();

0 commit comments

Comments
 (0)