apirest.md 49.8 KB
Newer Older
Remi Collet's avatar
Remi Collet committed
1
# GLPI REST API:  Documentation
Alexandre Delaunay's avatar
Alexandre Delaunay committed
2

3
## Summary
Alexandre Delaunay's avatar
Alexandre Delaunay committed
4 5 6

* [Glossary](#glossary)
* [Important](#important)
7 8
* [Init session](#init-session)
* [Kill session](#kill-session)
9
* [Lost password](#lost-password)
10 11 12 13 14 15 16
* [Get my profiles](#get-my-profiles)
* [Get active profile](#get-active-profile)
* [Change active profile](#change-active-profile)
* [Get my entities](#get-my-entities)
* [Get active entities](#get-active-entities)
* [Change active entities](#change-active-entities)
* [Get full session](#get-full-session)
Remi Collet's avatar
Remi Collet committed
17
* [Get GLPI config](#get-glpi-config)
18 19 20
* [Get an item](#get-an-item)
* [Get all items](#get-all-items)
* [Get sub items](#get-sub-items)
21
* [Get multiple items](#get-multiple-items)
22 23
* [List searchOptions](#list-searchoptions)
* [Search items](#search-items)
24 25 26
* [Add item(s)](#add-items)
* [Update item(s)](#update-items)
* [Delete item(s)](#delete-items)
27
* [Special cases](#special-cases)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
28
* [Errors](#errors)
29
* [Servers configuration](#servers-configuration)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
30

31
## Glossary
Alexandre Delaunay's avatar
Alexandre Delaunay committed
32

Alexandre Delaunay's avatar
Alexandre Delaunay committed
33 34 35 36 37 38 39 40
Endpoint
:   Resource available though the api.
    The endpoint is the URL where your api can be accessed by a client application

Method
:   HTTP verbs to indicate the desired action to be performed on the identified resource.
    See: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

Alexandre Delaunay's avatar
Alexandre Delaunay committed
41
itemtype
Alexandre Delaunay's avatar
Alexandre Delaunay committed
42
:   A GLPI type, could be an asset, an itil or a configuration object, etc.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
43
    This type must be a class who inherits CommonDTBM GLPI class.
44
    See [List itemtypes](https://forge.glpi-project.org/apidoc/class-CommonDBTM.html).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
45 46

searchOption
Alexandre Delaunay's avatar
Alexandre Delaunay committed
47
:   A column identifier (integer) of an itemtype (ex: 1 -> id, 2 -> name, ...).
48
    See [List searchOptions](#list-searchoptions) endpoint.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
49 50 51 52

JSON Payload
:   content of HTTP Request in json format (HTTP body)

Alexandre Delaunay's avatar
Alexandre Delaunay committed
53
Query string
Alexandre Delaunay's avatar
Alexandre Delaunay committed
54 55
:   URL parameters

Alexandre Delaunay's avatar
Alexandre Delaunay committed
56 57 58 59
User token
:   Used in login process instead of login/password couple.
    It represent the user with a string.
    You can find user token in the settings tabs of users.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
60

Alexandre Delaunay's avatar
Alexandre Delaunay committed
61 62 63 64 65 66 67 68
Session token
:   A string describing a valid session in glpi.
    Except initSession endpoint who provide this token, all others require this string to be used.

App(lication) token
:   An optional way to filter the access to the api.
    On api call, it will try to find an api client matching your ip and the app toekn (if provided).
    You can define an api client with an app token in general configuration for each of your external applications to identify them (each api client have its own history).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
69

70
## Important
Alexandre Delaunay's avatar
Alexandre Delaunay committed
71 72 73

* you should always precise a Content-Type header in your HTTP calls.
   Currently, the api supports:
74
  * application/json
75
  * multipart/form-data (for files upload, see [Add item(s)](#add-item-s) endpoint.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
76 77 78 79 80 81

* GET requests must have an empty body. You must pass all parameters in URL.
  Failing to do so will trigger an HTTP 400 response.

* By default, sessions used in this API are read-only.
  Only Some methods have write access to session:
82 83 84
  * [initSession](#init-session)
  * [killSession](#kill-session)
  * [changeActiveEntities](#change-active-entities)
85
  * [changeActiveProfile](#change-active-profile)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
86 87 88 89 90

  You could pass an additional parameter "session_write=true" to bypass this default.
  This read-only mode allow to use this API with parallel calls.
  In write mode, sessions are locked and your client must wait the end of a call before the next one can execute.

Remi Collet's avatar
Remi Collet committed
91
* You can filter API access by enable the following parameters in GLPI General Configuration (API tab):
92 93 94
  * IPv4 range
  * IPv6 address
  * *App-Token* parameter: if not empty, you should pass this parameter in all of your api calls
Alexandre Delaunay's avatar
Alexandre Delaunay committed
95

Alexandre Delaunay's avatar
Alexandre Delaunay committed
96 97
* Session and App tokens could be provided in query string instead of header parameters.

98
## Init session
Alexandre Delaunay's avatar
Alexandre Delaunay committed
99

100
* **URL**: apirest.php/initSession/
Alexandre Delaunay's avatar
Alexandre Delaunay committed
101 102
* **Description**: Request a session token to uses other api endpoints.
* **Method**: GET
103
* **Parameters**: (Headers)
Remi Collet's avatar
Remi Collet committed
104
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
105 106 107
  * a couple *login* & *password*: 2 parameters to login with user authentication.
     You should pass this 2 parameters in [http basic auth](https://en.wikipedia.org/wiki/Basic_access_authentication).
     It consists in a Base64 string with login and password separated by ":"
Alexandre Delaunay's avatar
Alexandre Delaunay committed
108
     A valid Authorization header is:
109
        * "Authorization: Basic base64({login}:{password})"
Alexandre Delaunay's avatar
Alexandre Delaunay committed
110

111
    > **OR**
Alexandre Delaunay's avatar
Alexandre Delaunay committed
112

113
  * an *user_token* defined in User Preference (See 'Remote access key')
Alexandre Delaunay's avatar
Alexandre Delaunay committed
114
     You should pass this parameter in 'Authorization' HTTP header.
115
     A valid Authorization header is:
116
        * "Authorization: user_token q56hqkniwot8wntb3z1qarka5atf365taaa2uyjrn"
Alexandre Delaunay's avatar
Alexandre Delaunay committed
117 118

* **Returns**:
119 120 121
  * 200 (OK) with the *session_token* string.
  * 400 (Bad Request) with a message indicating an error in input parameter.
  * 401 (UNAUTHORIZED)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
122 123 124 125 126 127 128

Examples usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
-H "Authorization: Basic Z2xwaTpnbHBp" \
129
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
130
'http://path/to/glpi/apirest.php/initSession'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
131 132 133 134 135 136 137 138

< 200 OK
< {
   "session_token": "83af7e620c83a50a18d3eac2f6ed05a3ca0bea62"
}

$ curl -X GET \
-H 'Content-Type: application/json' \
139
-H "Authorization: user_token q56hqkniwot8wntb3z1qarka5atf365taaa2uyjrn" \
140
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
141
'http://path/to/glpi/apirest.php/initSession'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
142 143 144 145 146 147 148

< 200 OK
< {
   "session_token": "83af7e620c83a50a18d3eac2f6ed05a3ca0bea62"
}
```

149
## Kill session
Alexandre Delaunay's avatar
Alexandre Delaunay committed
150

151
* **URL**: apirest.php/killSession/
Alexandre Delaunay's avatar
Alexandre Delaunay committed
152 153
* **Description**: Destroy a session identified by a session token.
* **Method**: GET
154 155
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
156
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
157 158 159
* **Returns**:
  * 200 (OK).
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
160 161 162 163 164 165

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
166 167
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
168
'http://path/to/glpi/apirest.php/killSession'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
169 170 171 172

< 200 OK
```

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
## Lost password

This endpoint allows to request password recovery and password reset. This endpoint works under the following 
conditions:
* GLPI has notifications enabled
* the email address of the user belongs to a user account.

Reset password request:

* **URL**: apirest.php/lostPassword/
* **Description**: Sends a notification to the user to reset his password
* **Method**: PUT
* **Parameters**: (JSON Payload)
  * *email*: email address of the user to recover. Mandatory.
* **Returns**:
  * 200 (OK).
  * 400 (Bad Request) with a message indicating an error in input parameter.

```bash
$ curl -X PUT \
-H 'Content-Type: application/json' \
-d '{"email": "user@domain.com"}' \
'http://path/to/glpi/apirest.php/lostPassword'

< 200 OK
```

Password reset :

* **URL**: apirest.php/lostPassword/
* **Description**: Sends a notification to the user to reset his password
* **Method**: PUT
* **Parameters**: (JSON Payload)
  * *email*: email address of the user to recover. Mandatory.
  * *password_forget_token*: reset token
  * *password*: the new password for the user
* **Returns**:
  * 200 (OK).
  * 400 (Bad Request) with a message indicating an error in input parameter.

```bash
$ curl -X PUT \
-H 'Content-Type: application/json' \
-d '{"email": "user@domain.com", \
     "password_forget_token": "b0a4cfe81448299ebed57442f4f21929c80ebee5" \
     "password": "NewPassword" \
    }' \
'http://path/to/glpi/apirest.php/lostPassword'

< 200 OK
```

225
## Get my profiles
Alexandre Delaunay's avatar
Alexandre Delaunay committed
226

227 228
* **URL**: [apirest.php/getMyProfiles/](getMyProfiles/?debug)
* **Description**: Return all the profiles associated to logged user.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
229
* **Method**: GET
230 231
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
232
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
233 234 235
* **Returns**:
  * 200 (OK) with an array of all profiles.
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
236 237 238 239

Example usage (CURL):

```bash
240
$ curl -X GET \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
241
-H 'Content-Type: application/json' \
242 243
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
244
'http://path/to/glpi/apirest.php/getMyProfiles'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
245 246

< 200 OK
247 248 249 250 251
< {
   'myprofiles': [
      {
         'id': 1
         'name': "Super-admin",
252
         'entities': [
253
            ...
254
         ],
255 256
         ...
      },
257 258
      ....
   ]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
259 260
```

261
## Get active profile
Alexandre Delaunay's avatar
Alexandre Delaunay committed
262

263
* **URL**: [apirest.php/getActiveProfile/](getActiveProfile/?debug)
264
* **Description**: Return the current active profile.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
265
* **Method**: GET
266 267
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
268
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
269 270 271
* **Returns**:
  * 200 (OK) with an array representing current profile.
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
272 273 274 275

Example usage (CURL):

```bash
276
$ curl -X GET \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
277
-H 'Content-Type: application/json' \
278 279
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
280
'http://path/to/glpi/apirest.php/getActiveProfile'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
281 282 283

< 200 OK
< {
284
      'name': "Super-admin",
285
      'entities': [
286
         ...
287
      ]
288
   }
Alexandre Delaunay's avatar
Alexandre Delaunay committed
289 290
```

291
## Change active profile
Alexandre Delaunay's avatar
Alexandre Delaunay committed
292

293
* **URL**: [apirest.php/changeActiveProfile/](changeActiveProfile/?profiles_id=4&debug)
294
* **Description**: Change active profile to the profiles_id one. See [getMyProfiles](#get-my-profiles) endpoint for possible profiles.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
295
* **Method**: POST
296 297
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
298
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
299 300 301 302 303
* **Parameters**: (JSON Payload)
  * *profiles_id*: (default 'all') ID of the new active profile. Mandatory.
* **Returns**:
  * 200 (OK).
  * 400 (Bad Request) with a message indicating an error in input parameter.
304
  * 404 (Not found) with a message indicating an error ig the profile does not exists or usable.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
305 306 307 308 309 310

Example usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
311 312
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
313
-d '{"profiles_id": 4}' \
314
'http://path/to/glpi/apirest.php/changeActiveProfile'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
315 316 317 318

< 200 OK
```

319
## Get my entities
Alexandre Delaunay's avatar
Alexandre Delaunay committed
320

321
* **URL**: [apirest.php/getMyEntities/](getMyEntities/?debug)
322
* **Description**: Return all the possible entities of the current logged user (and for current active profile).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
323
* **Method**: GET
324 325
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
326
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
327 328
* **Parameters**: (query string)
  * *is_recursive* (default: false): Also display sub entities of the active entity. Optionnal
329 330 331
* **Returns**:
  * 200 (OK) with an array of all entities (with id and name).
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
332 333 334 335 336 337

Example usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
338 339
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
340
'http://path/to/glpi/apirest.php/getMyEntities'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
341 342

< 200 OK
343 344 345 346 347 348
< {
   'myentities': [
     {
       'id':   71
       'name': "my_entity"
     },
Alexandre Delaunay's avatar
Alexandre Delaunay committed
349
   ....
350 351
   ]
  }
Alexandre Delaunay's avatar
Alexandre Delaunay committed
352 353
```

354
## Get active entities
Alexandre Delaunay's avatar
Alexandre Delaunay committed
355

356
* **URL**: [apirest.php/getActiveEntities/](getActiveEntities/?debug)
357
* **Description**: Return active entities of current logged user.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
358
* **Method**: GET
359 360
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
361
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
362 363 364 365 366 367
* **Returns**:
  * 200 (OK) with an array with 3 keys:
    * *active_entity*: current set entity.
    * *active_entity_recursive*: boolean, if we see sons of this entity.
    * *active_entities*: array all active entities (active_entity and its sons).
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
368 369 370 371 372 373

Example usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
374 375
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Johan Cwiklinski's avatar
Johan Cwiklinski committed
376
'http://path/to/glpi/apirest.php/getActiveEntities'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
377 378 379

< 200 OK
< {
380 381 382
   'active_entity': {
      'id': 1,
      'active_entity_recursive': true,
383 384 385 386
      'active_entities': [
        {"id":1},
        {"id":71},...
      ]
387
   }
388 389 390
}
```

391
## Change active entities
392 393

* **URL**: [apirest.php/changeActiveEntities/](changeActiveEntities/?entities_id=1&is_recursive=0&debug)
394
* **Description**: Change active entity to the entities_id one. See [getMyEntities](#get-my-entities) endpoint for possible entities.
395
* **Method**: POST
396 397
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
398
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
399 400 401 402 403 404
* **Parameters**: (JSON Payload)
  * *entities_id*: (default 'all') ID of the new active entity ("all" => load all possible entities). Optional.
  * *is_recursive*: (default false) Also display sub entities of the active entity.  Optional.
* **Returns**:
  * 200 (OK).
  * 400 (Bad Request) with a message indicating an error in input parameter.
405 406 407 408 409 410

Example usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
411 412
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
413 414 415 416
-d '{"entities_id": 1, "is_recursive": true}' \
'http://path/to/glpi/apirest.php/changeActiveEntities'

< 200 OK
Alexandre Delaunay's avatar
Alexandre Delaunay committed
417 418
```

419
## Get full session
Alexandre Delaunay's avatar
Alexandre Delaunay committed
420

421
* **URL**: [apirest.php/getFullSession/](getFullSession/?debug)
422
* **Description**: Return the current php $_SESSION.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
423
* **Method**: GET
424 425
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
426
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
427 428 429
* **Returns**:
  * 200 (OK) with an array representing the php session.
  * 400 (Bad Request) with a message indicating an error in input parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
430 431 432 433 434 435

Example usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
436 437
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
438
'http://path/to/glpi/apirest.php/getFullSession'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
439 440 441

< 200 OK
< {
442 443 444 445 446 447 448 449 450
      'session': {
         'glpi_plugins': ...,
         'glpicookietest': ...,
         'glpicsrftokens': ...,
         ...
      }
   }
```

Remi Collet's avatar
Remi Collet committed
451
## Get GLPI config
452 453 454 455 456 457

* **URL**: [apirest.php/getGlpiConfig/](getGlpiConfig/?debug)
* **Description**: Return the current $CFG_GLPI.
* **Method**: GET
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
458
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
459 460 461 462 463 464 465
* **Returns**:
  * 200 (OK) with an array representing the php global variable $CFG_GLPI.
  * 400 (Bad Request) with a message indicating an error in input parameter.

Example usage (CURL):

```bash
btry's avatar
btry committed
466
$ curl -X GET \
467 468 469 470 471 472 473 474 475 476 477 478 479
-H 'Content-Type: application/json' \
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
'http://path/to/glpi/apirest.php/getGlpiConfig'

< 200 OK
< {
      'cfg_glpi': {
         'languages': ...,
         'glpitables': ...,
         'unicity_types':...,
         ...
      }
Alexandre Delaunay's avatar
Alexandre Delaunay committed
480 481 482
   }
```

483
## Get an item
Alexandre Delaunay's avatar
Alexandre Delaunay committed
484

485
* **URL**: [apirest.php/:itemtype/:id](User/2?debug)
486
* **Description**: Return the instance fields of itemtype identified by id.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
487
* **Method**: GET
488 489
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
490
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
491 492 493 494 495
* **Parameters**: (query string)
  * *id*: unique identifier of the itemtype. Mandatory.
  * *expand_dropdowns* (default: false): show dropdown name instead of id. Optional.
  * *get_hateoas* (default: true): Show relations of the item in a links attribute. Optional.
  * *get_sha1* (default: false): Get a sha1 signature instead of the full answer. Optional.
496
  * *with_devices*: Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components. Optional.
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  * *with_disks*: Only for Computer, retrieve the associated file-systems. Optional.
  * *with_softwares*: Only for Computer, retrieve the associated software's installations. Optional.
  * *with_connections*: Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optional.
  * *with_networkports*: Retrieve all network's connections and advanced network's informations. Optional.
  * *with_infocoms*: Retrieve financial and administrative informations. Optional.
  * *with_contracts*: Retrieve associated contracts. Optional.
  * *with_documents*: Retrieve associated external documents. Optional.
  * *with_tickets*: Retrieve associated itil tickets. Optional.
  * *with_problems*: Retrieve associated itil problems. Optional.
  * *with_changes*: Retrieve associated itil changes. Optional.
  * *with_notes*: Retrieve Notes. Optional.
  * *with_logs*: Retrieve historical. Optional.
* **Returns**:
  * 200 (OK) with item data (Last-Modified header should contain the date of last modification of the item).
  * 401 (UNAUTHORIZED).
  * 404 (NOT FOUND).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
513 514 515 516 517 518

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
519 520
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
521
'http://path/to/glpi/apirest.php/Computer/71?expand_drodpowns=true'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
522 523 524

< 200 OK
< {
525
    "id": 71,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
    "entities_id": "Root Entity",
    "name": "adelaunay-ThinkPad-Edge-E320",
    "serial": "12345",
    "otherserial": "test2",
    "contact": "adelaunay",
    "contact_num": null,
    "users_id_tech": " ",
    "groups_id_tech": " ",
    "comment": "test222222qsdqsd",
    "date_mod": "2015-09-25 09:33:41",
    "operatingsystems_id": "Ubuntu 15.04",
    "operatingsystemversions_id": "15.04",
    "operatingsystemservicepacks_id": " ",
    "os_license_number": null,
    "os_licenseid": null,
    "autoupdatesystems_id": " ",
    "locations_id": "00:0e:08:3b:7d:04",
    "domains_id": "",
    "networks_id": " ",
    "computermodels_id": "1298A8G",
    "computertypes_id": "Notebook",
547
    "is_template": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
548 549
    "template_name": null,
    "manufacturers_id": "LENOVO",
550 551
    "is_deleted": 0,
    "is_dynamic": 1,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
    "users_id": "adelaunay",
    "groups_id": " ",
    "states_id": "Production",
    "ticket_tco": "0.0000",
    "uuid": "",
    "date_creation": null,
    "links": [{
       "rel": "Entity",
       "href": "http://path/to/glpi/api/Entity/0"
    }, {
       "rel": "OperatingSystem",
       "href": "http://path/to/glpi/api/OperatingSystem/32"
    }, {
       "rel": "OperatingSystemVersion",
       "href": "http://path/to/glpi/api/OperatingSystemVersion/48"
    }, {
       "rel": "Location",
       "href": "http://path/to/glpi/api/Location/3"
    }, {
       "rel": "Domain",
       "href": "http://path/to/glpi/api/Domain/18"
    }, {
       "rel": "ComputerModel",
       "href": "http://path/to/glpi/api/ComputerModel/11"
    }, {
       "rel": "ComputerType",
       "href": "http://path/to/glpi/api/ComputerType/3"
    }, {
       "rel": "Manufacturer",
       "href": "http://path/to/glpi/api/Manufacturer/260"
    }, {
       "rel": "User",
       "href": "http://path/to/glpi/api/User/27"
    }, {
       "rel": "State",
       "href": "http://path/to/glpi/api/State/1"
    }]
}
```

592
Note: To download a document see [Download a document file](#download-a-document-file).
593

594
## Get all items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
595

596
* **URL**: [apirest.php/:itemtype/](Computer/?debug)
597
* **Description**: Return a collection of rows of the itemtype.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
598
* **Method**: GET
599 600
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
601
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
602 603 604 605 606 607 608
* **Parameters**: (query string)
  * *expand_dropdowns* (default: false): show dropdown name instead of id. Optional.
  * *get_hateoas* (default: true): Show relation of item in a links attribute. Optional.
  * *only_id* (default: false): keep only id keys in returned data. Optional.
  * *range* (default: 0-50):  a string with a couple of number for start and end of pagination separated by a '-'. Ex: 150-200. Optional.
  * *sort* (default 1): id of the searchoption to sort by. Optional.
  * *order* (default ASC): ASC - Ascending sort / DESC Descending sort. Optional.
609
  * *searchText* (default NULL): array of filters to pass on the query (with key = field and value the text to search)
610
  * *is_deleted* (default: false): Return deleted element. Optional.
611 612 613 614
* **Returns**:
  * 200 (OK) with items data.
  * 206 (PARTIAL CONTENT) with items data defined by range.
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
615 616 617 618 619 620 621 622 623 624

   and theses headers:
      * *Content-Range* offset – limit / count
      * *Accept-Range* itemtype max

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
625 626
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
627
'http://path/to/glpi/apirest.php/Computer/?expand_drodpowns=true'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
628 629 630 631 632 633

< 200 OK
< Content-Range: 0-50/200
< Accept-Range: 990
< [
   {
634
      "id": 34,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
      "entities_id": "Root Entity",
      "name": "glpi",
      "serial": "VMware-42 01 f4 65 27 59 a9 fb-11 bc cd b8 64 68 1f 4b",
      "otherserial": null,
      "contact": "teclib",
      "contact_num": null,
      "users_id_tech": "&nbsp;",
      "groups_id_tech": "&nbsp;",
      "comment": "x86_64/00-09-15 08:03:28",
      "date_mod": "2011-12-16 17:52:55",
      "operatingsystems_id": "Ubuntu 10.04.2 LTS",
      "operatingsystemversions_id": "2.6.32-21-server",
      "operatingsystemservicepacks_id": "&nbsp;",
      "os_license_number": null,
      "os_licenseid": null,
      "autoupdatesystems_id": "FusionInventory",
      "locations_id": "&nbsp;",
      "domains_id": "teclib.infra",
      "networks_id": "&nbsp;",
      "computermodels_id": "VMware Virtual Platform",
      "computertypes_id": "Other",
656
      "is_template": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
657 658
      "template_name": null,
      "manufacturers_id": "VMware, Inc.",
659 660
      "is_deleted": 0,
      "is_dynamic": 1,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
      "users_id": "&nbsp;",
      "groups_id": "&nbsp;",
      "states_id": "Production",
      "ticket_tco": "0.0000",
      "uuid": "4201F465-2759-A9FB-11BC-CDB864681F4B",
      "links": [{
         "rel": "Entity",
         "href": "http://path/to/glpi/api/Entity/0"
      }, {
         "rel": "OperatingSystem",
         "href": "http://path/to/glpi/api/OperatingSystem/17"
      }, {
         "rel": "OperatingSystemVersion",
         "href": "http://path/to/glpi/api/OperatingSystemVersion/16"
      }, {
         "rel": "AutoUpdateSystem",
         "href": "http://path/to/glpi/api/AutoUpdateSystem/1"
      }, {
         "rel": "Domain",
         "href": "http://path/to/glpi/api/Domain/12"
      }, {
         "rel": "ComputerModel",
         "href": "http://path/to/glpi/api/ComputerModel/1"
      }, {
         "rel": "ComputerType",
         "href": "http://path/to/glpi/api/ComputerType/2"
      }, {
         "rel": "Manufacturer",
         "href": "http://path/to/glpi/api/Manufacturer/1"
      }, {
         "rel": "State",
         "href": "http://path/to/glpi/api/State/1"
      }]
   },
   {
696
      "id": 35,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
      "entities_id": "Root Entity",
      "name": "mavm1",
      "serial": "VMware-42 20 d3 04 ac 49 ed c8-ea 15 50 49 e1 40 0f 6c",
      "otherserial": null,
      "contact": "teclib",
      "contact_num": null,
      "users_id_tech": "&nbsp;",
      "groups_id_tech": "&nbsp;",
      "comment": "x86_64/01-01-04 19:50:40",
      "date_mod": "2012-05-24 06:43:35",
      "operatingsystems_id": "Ubuntu 10.04 LTS",
      "operatingsystemversions_id": "2.6.32-21-server",
      "operatingsystemservicepacks_id": "&nbsp;",
      "os_license_num"
      ...
   }
]
```

716
## Get sub items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
717

718
* **URL**: [apirest.php/:itemtype/:id/:sub_itemtype](User/2/Log?debug)
719
* **Description**: Return a collection of rows of the sub_itemtype for the identified item.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
720
* **Method**: GET
721 722
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
723
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
724 725 726 727 728 729 730 731 732 733 734
* **Parameters**: (query string)
  * id: unique identifier of the parent itemtype. Mandatory.
  * *expand_dropdowns* (default: false): show dropdown name instead of id. Optional.
  * *get_hateoas* (default: true): Show item's relations in a links attribute. Optional.
  * *only_id* (default: false): keep only id keys in returned data. Optional.
  * *range* (default: 0-50): a string with a couple of number for start and end of pagination separated by a '-' char. Ex: 150-200. Optional.
  * *sort* (default 1): id of the "searchoption" to sort by. Optional.
  * *order* (default ASC): ASC - Ascending sort / DESC Descending sort. Optional.
* **Returns**:
  * 200 (OK) with the items data.
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
735 736 737 738 739 740 741 742 743 744

   and theses headers:
      * *Content-Range* offset – limit / count
      * *Accept-Range* itemtype max

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
745 746
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
747
'http://path/to/glpi/apirest.php/User/2/Log'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
748 749 750 751 752 753

< 200 OK
< Content-Range: 0-50/200
< Accept-Range: 990
< [
   {
754
      "id": 22117,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
755
      "itemtype": "User",
756
      "items_id": 2,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
757
      "itemtype_link": "Profile",
758
      "linked_action": 17,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
759 760
      "user_name": "glpi (27)",
      "date_mod": "2015-10-13 10:00:59",
761
      "id_search_option": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
762 763 764
      "old_value": "",
      "new_value": "super-admin (4)"
   }, {
765
      "id": 22118,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
766
      "itemtype": "User",
767
      "items_id": 2,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
768
      "itemtype_link": "",
769
      "linked_action": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
770 771
      "user_name": "glpi (2)",
      "date_mod": "2015-10-13 10:01:22",
772
      "id_search_option": 80,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
773 774 775 776 777 778 779 780
      "old_value": "Root entity (0)",
      "new_value": "Root entity > my entity (1)"
   }, {
      ...
   }
]
```

781 782 783 784 785
## Get multiple items

* **URL**: apirest.php/getMultipleItems
* **Description**: Virtually call [Get an item](#get-an-item) for each line in input. So, you can have a ticket, an user in the same query.
* **Method**: GET
786 787
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
788
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
789 790
* **Parameters**: (query string)
  * *items*: items to retrieve. Mandatory.
791
              Each line of this array should contains two keys:
792 793 794 795 796
              * itemtype
              * items_id
  * *expand_dropdowns* (default: false): show dropdown name instead of id. Optional.
  * *get_hateoas* (default: true): Show relations of the item in a links attribute. Optional.
  * *get_sha1* (default: false): Get a sha1 signature instead of the full answer. Optional.
797
  * *with_devices*: Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components. Optional.
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
  * *with_disks*: Only for Computer, retrieve the associated file-systems. Optional.
  * *with_softwares*: Only for Computer, retrieve the associated software's installations. Optional.
  * *with_connections*: Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optional.
  * *with_networkports*: Retrieve all network's connections and advanced network's informations. Optional.
  * *with_infocoms*: Retrieve financial and administrative informations. Optional.
  * *with_contracts*: Retrieve associated contracts. Optional.
  * *with_documents*: Retrieve associated external documents. Optional.
  * *with_tickets*: Retrieve associated itil tickets. Optional.
  * *with_problems*: Retrieve associated itil problems. Optional.
  * *with_changes*: Retrieve associated itil changes. Optional.
  * *with_notes*: Retrieve Notes. Optional.
  * *with_logs*: Retrieve historical. Optional.
* **Returns**:
  * 200 (OK) with item data (Last-Modified header should contain the date of last modification of the item).
  * 401 (UNAUTHORIZED).
  * 404 (NOT FOUND).
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
-d '{"items": [{"itemtype": "User", "items_id": 2}, {"itemtype": "Entity", "items_id": 0}]}' \
'http://path/to/glpi/apirest.php/getMultipleItems?items\[0\]\[itemtype\]\=User&items\[0\]\[items_id\]\=2&items\[1\]\[itemtype\]\=Entity&items\[1\]\[items_id\]\=0'

< 200 OK
< Content-Range: 0-50/200
< Accept-Range: 990
< [{
   "id": 2,
   "name": "glpi",
   ...
}, {
   "id": 0,
   "name": "Root Entity",
   ...
}]
```

839
## List searchOptions
Alexandre Delaunay's avatar
Alexandre Delaunay committed
840

841
* **URL**: [apirest.php/listSearchOptions/:itemtype](listSearchOptions/Computer?debug)
842
* **Description**: List the searchoptions of provided itemtype. To use with [Search items](#search_items).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
843
* **Method**: GET
844 845
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
846
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
847 848 849 850 851
* **Parameters**: (query string)
  * *raw*: return searchoption uncleaned (as provided by core)
* **Returns**:
  * 200 (OK) with all searchoptions of specified itemtype (format: searchoption_id: {option_content}).
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
852 853 854 855 856 857

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
858 859
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
860
'http://path/to/glpi/apirest.php/listSearchOptions/Computer'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
< 200 OK
< {
    "common": "Characteristics",

    1: {
      'name': 'Name'
      'table': 'glpi_computers'
      'field': 'name'
      'linkfield': 'name'
      'datatype': 'itemlink'
      'uid': 'Computer.name'
   },
   2: {
      'name': 'ID'
      'table': 'glpi_computers'
      'field': 'id'
      'linkfield': 'id'
      'datatype': 'number'
      'uid': 'Computer.id'
   },
   3: {
      'name': 'Location'
      'table': 'glpi_locations'
      'field': 'completename'
      'linkfield': 'locations_id'
      'datatype': 'dropdown'
      'uid': 'Computer.Location.completename'
   },
   ...
}
```

893
## Search items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
894

895
* **URL**: [apirest.php/search/:itemtype/](search/Computer/?debug)
Remi Collet's avatar
Remi Collet committed
896
* **Description**: Expose the GLPI searchEngine and combine criteria to retrieve a list of elements of specified itemtype.
897
  > Note: you can use 'AllAssets' itemtype to retrieve a combination of all asset's types.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
898
* **Method**: GET
899 900
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
901
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
902 903
* **Parameters**: (query string)
  * *criteria*: array of criterion objects to filter search. Optional.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
904
      Each criterion object must provide:
905 906
        * *link*: (optional for 1st element) logical operator in [AND, OR, AND NOT, AND NOT].
        * *field*: id of the searchoption.
907
        * *searchtype*: type of search in [contains¹, equals², notequals², lessthan, morethan, under, notunder].
908
        * *value*: the value to search.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923

      Ex:

         ```javascript
         ...
         "criteria":
            [
               {
                  "field":      1,
                  "searchtype": 'contains',
                  "value":      ''
               }, {
                  "link":       'AND',
                  "field":      31,
                  "searchtype": 'equals',
924
                  "value":      1
Alexandre Delaunay's avatar
Alexandre Delaunay committed
925 926 927 928 929
                }
            ]
         ...
         ```

930 931
  * *metacriteria* (optional): array of meta-criterion objects to filter search. Optional.
                                 A meta search is a link with another itemtype (ex: Computer with softwares).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
932
      Each meta-criterion object must provide:
933 934 935
        * *link*: logical operator in [AND, OR, AND NOT, AND NOT]. Mandatory.
        * *itemtype*: second itemtype to link.
        * *field*: id of the searchoption.
936
        * *searchtype*: type of search in [contains¹, equals², notequals², lessthan, morethan, under, notunder].
937
        * *value*: the value to search.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961

      Ex:

         ```javascript
         ...
         "metacriteria":
            [
               {
                  "link":       'AND',
                  "itemtype":   'Monitor',
                  "field":      2,
                  "searchtype": 'contains',
                  "value":      ''
               }, {
                  "link":       'AND',
                  "itemtype":   'Monitor',
                  "field":      3,
                  "searchtype": 'contains',
                  "value":      ''
                }
            ]
         ...
         ```

962 963 964
  * *sort* (default 1): id of the searchoption to sort by. Optional.
  * *order* (default ASC): ASC - Ascending sort / DESC Descending sort. Optional.
  * *range* (default 0-50): a string with a couple of number for start and end of pagination separated by a '-'. Ex: 150-200.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
965
                             Optional.
966
  * *forcedisplay*: array of columns to display (default empty = use display preferences and searched criteria).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
967 968
                     Some columns will be always presents (1: id, 2: name, 80: Entity).
                     Optional.
969 970 971
  * *rawdata* (default false): a boolean for displaying raws data of the Search engine of glpi (like SQL request, full searchoptions, etc)
  * *withindexes* (default false): a boolean to retrieve rows indexed by items id.
   By default this option is set to false, because order of json objects (which are identified by index) cannot be garrantued  (from <http://json.org/> : An object is an unordered set of name/value pairs).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
972
   So, we provide arrays to guarantying sorted rows.
973 974
  * *uid_cols* (default false): a boolean to identify cols by the 'uniqid' of the searchoptions instead of a numeric value (see [List searchOptions](#list-searchoptions) and 'uid' field)
  * *giveItems* (default false): a boolean to retrieve the data with the html parsed from core, new data are provided in data_html key.
975 976 977 978

  * ¹ - *contains* will use a wildcard search per default. You can restrict at the beginning using the *^* character, and/or at the end using the *$* character.
  * ² - *equals* and *notequals* are designed to be used with dropdowns. Do not expect those operators to search for a strictly equal value (see ¹ above).

979 980
* **Returns**:
  * 200 (OK) with all rows data with this format:
Alexandre Delaunay's avatar
Alexandre Delaunay committed
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000

   ```javascript
      {
          "totalcount": ":numberofresults_without_pagination",
          "range": ":start-:end",
          "data": {
              ":items_id": {
                  ":searchoptions_id": "value",
                  ...
              },
              ":items_id": {
               ...
             }
         },
         "rawdata": {
            ...
         }
      }
   ```

1001 1002
  * 206 (PARTIAL CONTENT) with rows data (pagination doesn't permit to display all rows).
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012

   and theses headers:
      * *Content-Range* offset – limit / count
      * *Accept-Range* itemtype max

Example usage (CURL):

```bash
curl -g -X GET \
-H 'Content-Type: application/json' \
1013 1014
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
1015 1016
'http://path/to/glpi/apirest.php/search/Monitor?\
criteria\[0\]\[link\]\=AND\
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1017 1018 1019 1020 1021 1022 1023 1024 1025
\&criteria\[0\]\[itemtype\]\=Monitor\
\&criteria\[0\]\[field\]\=23\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=GSM\
\&criteria\[1\]\[link\]\=AND\
\&criteria\[1\]\[itemtype\]\=Monitor\
\&criteria\[1\]\[field\]\=1\
\&criteria\[1\]\[searchtype\]\=contains\
\&criteria\[1\]\[value\]\=W2\
1026
\&range\=0-2\&&forcedisplay\[0\]\=1'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1027 1028 1029 1030 1031 1032 1033

< 200 OK
< Content-Range: 0-2/2
< Accept-Range: 990
< {"totalcount":2,"count":2,"data":{"11":{"1":"W2242","80":"Root Entity","23":"GSM"},"7":{"1":"W2252","80":"Root Entity","23":"GSM"}}}%
```

1034
## Add item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1035

1036
* **URL**: apirest.php/:itemtype/
Remi Collet's avatar
Remi Collet committed
1037
* **Description**: Add an object (or multiple objects) into GLPI.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1038
* **Method**: POST
1039 1040
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
1041
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
1042 1043
* **Parameters**: (JSON Payload)
  * *input*: an object with fields of itemtype to be inserted.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1044 1045 1046 1047 1048
              You can add several items in one action by passing an array of objects.
              Mandatory.

   **Important:**
      In case of 'multipart/data' content_type (aka file upload), you should insert your parameters into
1049
      a 'uploadManifest' parameter.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1050 1051
      Theses serialized data should be a json string.

1052 1053 1054 1055 1056 1057 1058 1059
* **Returns**:
  * 201 (OK) with id of added items.
  * 207 (Multi-Status) with id of added items and errors.
  * 400 (Bad Request) with a message indicating an error in input parameter.
  * 401 (UNAUTHORIZED).
  * And additional header can be provided on creation success:
    * Location when adding a single item.
    * Link on bulk addition.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1060 1061 1062 1063 1064 1065

Examples usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
1066 1067
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1068
-d '{"input": {"name": "My single computer", "serial": "12345"}}' \
1069
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1070 1071 1072 1073 1074 1075 1076 1077

< 201 OK
< Location: http://path/to/glpi/api/Computer/15
< {"id": 15}


$ curl -X POST \
-H 'Content-Type: application/json' \
1078 1079
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1080
-d '{"input": [{"name": "My first computer", "serial": "12345"}, {"name": "My 2nd computer", "serial": "67890"}, {"name": "My 3rd computer", "serial": "qsd12sd"}]}' \
1081
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1082

1083
< 207 OK
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1084
< Link: http://path/to/glpi/api/Computer/8,http://path/to/glpi/api/Computer/9
1085
< [ {"id":8, "message": ""}, {"id":false, "message": "You don't have permission to perform this action."}, {"id":9, "message": ""} ]
1086

Alexandre Delaunay's avatar
Alexandre Delaunay committed
1087 1088
```

1089
Note: To upload a document see [Upload a document file](#upload-a-document-file).
1090

1091
## Update item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1092

1093
* **URL**: apirest.php/:itemtype/:id
Remi Collet's avatar
Remi Collet committed
1094
* **Description**: Update an object (or multiple objects) existing in GLPI.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1095
* **Method**: PUT
1096 1097
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
1098
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
1099 1100 1101
* **Parameters**: (JSON Payload)
  * *id*: the unique identifier of the itemtype passed in URL. You **could skip** this parameter by passing it in the input payload.
  * *input*: Array of objects with fields of itemtype to be updated.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1102 1103
               Mandatory.
               You **could provide** in each object a key named 'id' to identify the item(s) to update.
1104 1105 1106 1107 1108
* **Returns**:
  * 200 (OK) with update status for each item.
  * 207 (Multi-Status) with id of added items and errors.
  * 400 (Bad Request) with a message indicating an error in input parameter.
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1109 1110 1111 1112 1113 1114

Example usage (CURL):

```bash
$ curl -X PUT \
-H 'Content-Type: application/json' \
1115 1116
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1117
-d '{"input": {"otherserial": "xcvbn"}}' \
1118
'http://path/to/glpi/apirest.php/Computer/10'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1119 1120

< 200 OK
btry's avatar
btry committed
1121
[{"10":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1122 1123 1124 1125


$ curl -X PUT \
-H 'Content-Type: application/json' \
1126 1127
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1128
-d '{"input": {"id": 11,  "otherserial": "abcde"}}' \
1129
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1130 1131

< 200 OK
btry's avatar
btry committed
1132
[{"11":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1133 1134 1135 1136


$ curl -X PUT \
-H 'Content-Type: application/json' \
1137 1138
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1139
-d '{"input": [{"id": 16,  "otherserial": "abcde"}, {"id": 17,  "otherserial": "fghij"}]}' \
1140
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1141

1142
< 207 OK
1143
[{"8":true, "message": ""},{"2":false, "message": "Item not found"}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1144 1145
```

1146
## Delete item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1147

1148
* **URL**: apirest.php/:itemtype/:id
Remi Collet's avatar
Remi Collet committed
1149
* **Description**: Delete an object existing in GLPI.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1150
* **Method**: DELETE
1151 1152
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
Remi Collet's avatar
Remi Collet committed
1153
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
1154 1155
* **Parameters**: (query string)
  * *id*: unique identifier of the itemtype passed in the URL. You **could skip** this parameter by passing it in the input payload.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1156
      OR
1157
  * *input* Array of id who need to be deleted. This parameter is passed by payload.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1158 1159 1160

   id parameter has precedence over input payload.

1161
  * *force_purge* (default false): boolean, if the itemtype have a dustbin, you can force purge (delete finally).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1162
                     Optional.
1163
  * *history* (default true): boolean, set to false to disable saving of deletion in global history.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1164
                 Optional.
1165 1166 1167 1168 1169 1170
* **Returns**:
  * 200 (OK) *in case of multiple deletion*.
  * 204 (No Content) *in case of single deletion*.
  * 207 (Multi-Status) with id of deleted items and errors.
  * 400 (Bad Request) with a message indicating an error in input parameter.
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1171 1172 1173 1174 1175 1176

Example usage (CURL):

```bash
$ curl -X DELETE \
-H 'Content-Type: application/json' \
1177 1178
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
1179
'http://path/to/glpi/apirest.php/Computer/16?force_purge=true'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1180

btry's avatar
btry committed
1181 1182
< 200 OK
[{"16":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1183 1184 1185

$ curl -X DELETE \
-H 'Content-Type: application/json' \
1186 1187
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1188
-d '{"input": {"id": 11}, "force_purge": true}' \
1189
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1190 1191

< 200 OK
btry's avatar
btry committed
1192
[{"11":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1193 1194 1195 1196


$ curl -X DELETE \
-H 'Content-Type: application/json' \
1197 1198
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1199
-d '{"input": [{"id": 16}, {"id": 17}]}' \
1200
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1201 1202

< 207 OK
1203
[{"16":true, "message": ""},{"17":false, "message": "Item not found"}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1204 1205
```

1206 1207 1208 1209
## Special cases

### Upload a document file

1210
See [Add item(s)](#add-items) and apply specific instructions below.
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230

Uploading a file requires use of 'multipart/data' content_type. The input data must be send in a 'uploadManifest' parameter and use the json format.

Examples usage (CURL):

```shell
$ curl -X POST \
-H 'Content-Type: multipart/form-data' \
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
-F 'uploadManifest={"input": {"name": "Uploaded document", "_filename" : ["file.txt"]}};type=application/json' \
-F 'filename[0]=@file.txt' \
'http://path/to/glpi/apirest.php/Document/'

< 201 OK
< Location: http://path/to/glpi/api/Document/1
< {"id": 1, "message": "Document move succeeded.", "upload_result": {...}}

```

1231
### Download a document file
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279

* **URL**: apirest.php/Document/:id
* **Description**: Download a document.
* **Method**: GET
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
  * *App-Token*: authorization string provided by the GLPI api configuration. Optional.
  * *Accept*: must be **application/octet-stream**. This header OR the parameter *alt* is mandatory
* **Parameters**: (query string)
  * *id*: unique identifier of the itemtype passed in the URL. You **could skip** this parameter by passing it in the input payload.
  * *alt*: must be 'media'. This parameter or the header **Accept** is mandatory.

   id parameter has precedence over input payload.

* **Returns**:
  * 200 (OK) *in case of multiple deletion*.
  * 400 (Bad Request) with a message indicating an error in input parameter.
  * 401 (UNAUTHORIZED).

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
-H "Accept: application/octet-stream" \
-d '{"input": {"id": 11}}' \
'http://path/to/glpi/apirest.php/Document/'

< 200 OK
```

The body of the answer contains the raw file attached to the document.

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
-d '{"input": {"id": 11}}' \
'http://path/to/glpi/apirest.php/Document/&alt=media'

< 200 OK
```

The body of the answer contains the raw file attached to the document.

1280
## Errors
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1281

1282
### ERROR_ITEM_NOT_FOUND
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1283

Remi Collet's avatar
Remi Collet committed
1284
The desired resource (itemtype-id) was not found in the GLPI database.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1285

1286
### ERROR_BAD_ARRAY
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1287 1288 1289

The HTTP body must be an an array of objects.

1290
### ERROR_METHOD_NOT_ALLOWED
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1291 1292 1293

You specified an inexistent or not not allowed resource.

1294
### ERROR_RIGHT_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1295

1296
The current logged user miss rights in his profile to do the provided action.
Remi Collet's avatar
Remi Collet committed
1297
Alter this profile or choose a new one for the user in GLPI main interface.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1298

1299
### ERROR_SESSION_TOKEN_INVALID
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1300

1301
The Session-Token provided in header is invalid.
1302
You should redo an [Init session](#init-session) request.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1303

1304
### ERROR_SESSION_TOKEN_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1305 1306 1307

You miss to provide Session-Token in header of your HTTP request.

1308
### ERROR_APP_TOKEN_PARAMETERS_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1309 1310 1311

The current API requires an App-Token header for using its methods.

Alexandre Delaunay's avatar
Alexandre Delaunay committed
1312 1313 1314 1315
### ERROR_WRONG_APP_TOKEN_PARAMETER

It seems the provided application token doesn't exists in GLPI API configuration.

1316
### ERROR_NOT_DELETED
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1317