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

Commit 7832fec

Browse files
DIOHz0rajsb85
authored andcommittedOct 29, 2017
feat(example): added example for magic call of itemTypes.
1 parent 9eae107 commit 7832fec

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
 

‎example/magicCallExample.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* --------------------------------------------------------------------
4+
*
5+
* LICENSE
6+
*
7+
* This file is part of the GLPI API Client Library for PHP,
8+
* a subproject of GLPI. GLPI is a free IT Asset Management.
9+
*
10+
* GLPI is free software: you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 3
13+
* of the License, or (at your option) any later version.
14+
*
15+
* GLPI is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
* --------------------------------------------------------------------
20+
* @author Domingo Oropeza - <doropeza@teclib.com>
21+
* @copyright (C) 2017 Teclib' and contributors.
22+
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
23+
* @link https://github.com/glpi-project/php-library-glpi
24+
* @link http://www.glpi-project.org/
25+
* --------------------------------------------------------------------
26+
*/
27+
28+
require_once __DIR__ . '/../vendor/autoload.php';
29+
30+
$client = new \Glpi\Api\Rest\Client('http://localhost/glpi/apirest.php/');
31+
32+
try {
33+
// try to do login
34+
$client->initSessionByCredentials('glpi', 'glpi');
35+
} catch (Exception $e) {
36+
// print the error if failed
37+
echo $e->getMessage();
38+
die();
39+
}
40+
41+
// Let's work with item types
42+
$itemHandler = new \Glpi\Api\Rest\ItemHandler($client);
43+
44+
45+
// create a new computer
46+
$response = $itemHandler->Computer('create', ['name' => 'pc001', 'users_id' => 2]);
47+
print_r($response);
48+
49+
// get the computer created
50+
$computer = json_decode($response['body']);
51+
$response = $itemHandler->Computer('read', $computer->id, ['expand_dropdowns' => true]);
52+
print_r($response);
53+
54+
// update the computer description
55+
$response = $itemHandler->Computer('update', ['id' => $computer->id, 'name' => 'pc100']);
56+
print_r($response);
57+
58+
// delete de computer
59+
$response = $itemHandler->Computer('delete', ['id' => $computer->id], ['force_purge' => true]);
60+
print_r($response);
61+
62+
// let's end the session.
63+
$client->killSession();

0 commit comments

Comments
 (0)