apirest.md 49.9 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
Endpoint
34 35
:   Resource available though the API.
    The endpoint is the URL where your API can be accessed by a client application
Alexandre Delaunay's avatar
Alexandre Delaunay committed
36 37 38 39 40

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
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

JSON Payload
51
:   content of HTTP Request in JSON format (HTTP body)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
52

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
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
66
:   An optional way to filter the access to the API.
67
    On API call, it will try to find an API client matching your IP and the app token (if provided).
68
    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
* You should always provide a Content-Type header in your HTTP calls.
73
   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

* 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.
81
  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
  * IPv4 range
  * IPv6 address
94
  * *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/
101
* **Description**: Request a session token to uses other API endpoints.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
102
* **Method**: GET
103
* **Parameters**: (Headers)
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.
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
## 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
184
* **Method**: PUT or PATCH
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
* **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
204
* **Method**: PUT or PATCH
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
* **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.
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.
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.
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.
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

Example usage (CURL):

```bash
336
$ curl -X GET \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
337
-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.
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

Example usage (CURL):

```bash
372
$ curl -X GET \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
373
-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.
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.
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

Example usage (CURL):

```bash
434
$ curl -X GET \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
435
-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.
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.
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
  * *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.
504 505 506
  * *with_tickets*: Retrieve associated ITIL tickets. Optional.
  * *with_problems*: Retrieve associated ITIL problems. Optional.
  * *with_changes*: Retrieve associated ITIL changes. Optional.
507 508 509 510 511 512
  * *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_dropdowns=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
    "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",
    "autoupdatesystems_id": " ",
    "locations_id": "00:0e:08:3b:7d:04",
    "domains_id": "",
    "networks_id": " ",
    "computermodels_id": "1298A8G",
    "computertypes_id": "Notebook",
542
    "is_template": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
543 544
    "template_name": null,
    "manufacturers_id": "LENOVO",
545 546
    "is_deleted": 0,
    "is_dynamic": 1,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
547 548 549 550 551 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
    "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": "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"
    }]
}
```

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

583
## Get all items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
584

585
* **URL**: [apirest.php/:itemtype/](Computer/?debug)
586
* **Description**: Return a collection of rows of the itemtype.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
587
* **Method**: GET
588 589
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
590
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
591 592 593 594 595 596 597
* **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.
598
  * *searchText* (default NULL): array of filters to pass on the query (with key = field and value the text to search)
599
  * *is_deleted* (default: false): Return deleted element. Optional.
600 601 602 603
* **Returns**:
  * 200 (OK) with items data.
  * 206 (PARTIAL CONTENT) with items data defined by range.
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
604 605 606 607 608 609 610 611 612 613

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

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
614 615
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
616
'http://path/to/glpi/apirest.php/Computer/?expand_dropdowns=true'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
617

618
< 206 OK
Alexandre Delaunay's avatar
Alexandre Delaunay committed
619 620 621 622
< Content-Range: 0-50/200
< Accept-Range: 990
< [
   {
623
      "id": 34,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
      "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",
      "autoupdatesystems_id": "FusionInventory",
      "locations_id": "&nbsp;",
      "domains_id": "teclib.infra",
      "networks_id": "&nbsp;",
      "computermodels_id": "VMware Virtual Platform",
      "computertypes_id": "Other",
640
      "is_template": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
641 642
      "template_name": null,
      "manufacturers_id": "VMware, Inc.",
643 644
      "is_deleted": 0,
      "is_dynamic": 1,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
      "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": "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"
      }]
   },
   {
674
      "id": 35,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
      "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",
      ...
   }
]
```

690
## Get sub items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
691

692
* **URL**: [apirest.php/:itemtype/:id/:sub_itemtype](User/2/Log?debug)
693
* **Description**: Return a collection of rows of the sub_itemtype for the identified item.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
694
* **Method**: GET
695 696
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
697
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
698 699 700 701 702 703 704 705 706 707 708
* **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
709 710 711 712 713 714 715 716 717 718

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

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
719 720
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
721
'http://path/to/glpi/apirest.php/User/2/Log'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
722 723 724 725 726 727

< 200 OK
< Content-Range: 0-50/200
< Accept-Range: 990
< [
   {
728
      "id": 22117,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
729
      "itemtype": "User",
730
      "items_id": 2,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
731
      "itemtype_link": "Profile",
732
      "linked_action": 17,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
733 734
      "user_name": "glpi (27)",
      "date_mod": "2015-10-13 10:00:59",
735
      "id_search_option": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
736 737 738
      "old_value": "",
      "new_value": "super-admin (4)"
   }, {
739
      "id": 22118,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
740
      "itemtype": "User",
741
      "items_id": 2,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
742
      "itemtype_link": "",
743
      "linked_action": 0,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
744 745
      "user_name": "glpi (2)",
      "date_mod": "2015-10-13 10:01:22",
746
      "id_search_option": 80,
Alexandre Delaunay's avatar
Alexandre Delaunay committed
747 748 749 750 751 752 753 754
      "old_value": "Root entity (0)",
      "new_value": "Root entity > my entity (1)"
   }, {
      ...
   }
]
```

755 756 757
## Get multiple items

* **URL**: apirest.php/getMultipleItems
758
* **Description**: Virtually call [Get an item](#get-an-item) for each line in input. So, you can have a ticket, a user in the same query.
759
* **Method**: GET
760 761
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
762
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
763 764
* **Parameters**: (query string)
  * *items*: items to retrieve. Mandatory.
765
              Each line of this array should contains two keys:
766 767 768 769 770
              * 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.
771
  * *with_devices*: Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components. Optional.
772 773 774 775 776 777 778
  * *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.
779 780 781
  * *with_tickets*: Retrieve associated ITIL tickets. Optional.
  * *with_problems*: Retrieve associated ITIL problems. Optional.
  * *with_changes*: Retrieve associated ITIL changes. Optional.
782 783 784 785 786 787
  * *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).
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812

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",
   ...
}]
```

813
## List searchOptions
Alexandre Delaunay's avatar
Alexandre Delaunay committed
814

815
* **URL**: [apirest.php/listSearchOptions/:itemtype](listSearchOptions/Computer?debug)
816
* **Description**: List the searchoptions of provided itemtype. To use with [Search items](#search_items).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
817
* **Method**: GET
818 819
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
820
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
821 822 823 824 825
* **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
826 827 828 829 830 831

Example usage (CURL):

```bash
$ curl -X GET \
-H 'Content-Type: application/json' \
832 833
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
834
'http://path/to/glpi/apirest.php/listSearchOptions/Computer'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
< 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'
   },
   ...
}
```

867
## Search items
Alexandre Delaunay's avatar
Alexandre Delaunay committed
868

869
* **URL**: [apirest.php/search/:itemtype/](search/Computer/?debug)
Remi Collet's avatar
Remi Collet committed
870
* **Description**: Expose the GLPI searchEngine and combine criteria to retrieve a list of elements of specified itemtype.
871
  > Note: you can use 'AllAssets' itemtype to retrieve a combination of all asset's types.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
872
* **Method**: GET
873 874
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
875
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
876 877
* **Parameters**: (query string)
  * *criteria*: array of criterion objects to filter search. Optional.
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
    You can optionally precise `meta=true` to pass a searchoption of another itemtype (meta-criteria).
    Each criterion object must provide at least:
      * *link*: (optional for 1st element) logical operator in [AND, OR, AND NOT, AND NOT].

      And you can pass a direct searchoption usage :

      * *field*: id of the searchoption.
      * *meta*: boolean, is this criterion a meta one ?
      * *itemtype*: for meta=true criterion, precise the itemtype to use.
      * *searchtype*: type of search in [contains¹, equals², notequals², lessthan, morethan, under, notunder].
      * *value*: the value to search.

      Or a list of sub-nodes with the key:

      * *criteria*: nested criteria inside this criteria.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
893 894 895

      Ex:

896
      ```json
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
      ...
      "criteria":
         [
            {
               "field":      1,
               "searchtype": 'contains',
               "value":      ''
            }, {
               "link":       'AND',
               "field":      31,
               "searchtype": 'equals',
               "value":      1
            }, {
               "link":       'AND',
               "meta":       true,
               "itemtype":   'User',
               "field":      1,
               "searchtype": 'equals',
               "value":      1
            }, {
               "link":       'AND',
               "criteria" : [
                  {
                     "field":      34,
                     "searchtype": 'equals',
                     "value":      1
                  }, {
                     "link":       'OR',
                     "field":      35,
                     "searchtype": 'equals',
                     "value":      1
                  }
               ]
            }
         ]
      ...
      ```
Alexandre Delaunay's avatar
Alexandre Delaunay committed
934

935
  * *metacriteria* (optional): array of meta-criterion objects to filter search. Optional.
936 937 938
                                 A meta search is a link with another itemtype (ex: Computer with softwares).  
      **Deprecated: Now criteria support meta flag, you should use it instead direct metacriteria option.**

Alexandre Delaunay's avatar
Alexandre Delaunay committed
939
      Each meta-criterion object must provide:
940 941 942
        * *link*: logical operator in [AND, OR, AND NOT, AND NOT]. Mandatory.
        * *itemtype*: second itemtype to link.
        * *field*: id of the searchoption.
943
        * *searchtype*: type of search in [contains¹, equals², notequals², lessthan, morethan, under, notunder].
944
        * *value*: the value to search.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
945 946 947

      Ex:

948
      ```json
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
      ...
      "metacriteria":
         [
            {
               "link":       'AND',
               "itemtype":   'Monitor',
               "field":      2,
               "searchtype": 'contains',
               "value":      ''
            }, {
               "link":       'AND',
               "itemtype":   'Monitor',
               "field":      3,
               "searchtype": 'contains',
               "value":      ''
             }
         ]
      ...
      ```
Alexandre Delaunay's avatar
Alexandre Delaunay committed
968

969 970 971
  * *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
972
                             Optional.
973
  * *forcedisplay*: array of columns to display (default empty = use display preferences and searched criteria).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
974 975
                     Some columns will be always presents (1: id, 2: name, 80: Entity).
                     Optional.
976
  * *rawdata* (default false): a boolean for displaying raws data of the Search engine of GLPI (like SQL request, full searchoptions, etc)
977
  * *withindexes* (default false): a boolean to retrieve rows indexed by items id.
978
   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
979
   So, we provide arrays to guarantying sorted rows.
980 981
  * *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.
982 983 984 985

  * ¹ - *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).

986 987
* **Returns**:
  * 200 (OK) with all rows data with this format:
Alexandre Delaunay's avatar
Alexandre Delaunay committed
988

989
     ```json
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
        {
            "totalcount": ":numberofresults_without_pagination",
            "range": ":start-:end",
            "data": {
                ":items_id": {
                    ":searchoptions_id": "value",
                    ...
                },
                ":items_id": {
                 ...
               }
           },
           "rawdata": {
              ...
           }
        }
     ```
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1007

1008 1009
  * 206 (PARTIAL CONTENT) with rows data (pagination doesn't permit to display all rows).
  * 401 (UNAUTHORIZED).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1010

1011
      and theses headers:
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1012 1013 1014 1015 1016 1017 1018 1019
      * *Content-Range* offset – limit / count
      * *Accept-Range* itemtype max

Example usage (CURL):

```bash
curl -g -X GET \
-H 'Content-Type: application/json' \
1020 1021
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
1022 1023
'http://path/to/glpi/apirest.php/search/Monitor?\
criteria\[0\]\[link\]\=AND\
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1024 1025 1026 1027 1028 1029 1030 1031 1032
\&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\
1033
\&range\=0-2\&&forcedisplay\[0\]\=1'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1034 1035 1036 1037 1038 1039 1040

< 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"}}}%
```

1041
## Add item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1042

1043
* **URL**: apirest.php/:itemtype/
Remi Collet's avatar
Remi Collet committed
1044
* **Description**: Add an object (or multiple objects) into GLPI.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1045
* **Method**: POST
1046 1047
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
1048
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
1049 1050
* **Parameters**: (JSON Payload)
  * *input*: an object with fields of itemtype to be inserted.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1051 1052 1053 1054 1055
              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
1056
      a 'uploadManifest' parameter.
1057
      Theses serialized data should be a JSON string.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1058

1059 1060 1061 1062 1063 1064 1065 1066
* **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
1067 1068 1069 1070 1071 1072

Examples usage (CURL):

```bash
$ curl -X POST \
-H 'Content-Type: application/json' \
1073 1074
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1075
-d '{"input": {"name": "My single computer", "serial": "12345"}}' \
1076
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1077 1078 1079 1080 1081 1082 1083 1084

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


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

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

Alexandre Delaunay's avatar
Alexandre Delaunay committed
1094 1095
```

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

1098
## Update item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1099

1100
* **URL**: apirest.php/:itemtype/:id
Remi Collet's avatar
Remi Collet committed
1101
* **Description**: Update an object (or multiple objects) existing in GLPI.
1102
* **Method**: PUT or PATCH
1103 1104
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
1105
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
1106 1107 1108
* **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
1109 1110
               Mandatory.
               You **could provide** in each object a key named 'id' to identify the item(s) to update.
1111 1112 1113 1114 1115
* **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
1116 1117 1118 1119 1120 1121

Example usage (CURL):

```bash
$ curl -X PUT \
-H 'Content-Type: application/json' \
1122 1123
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1124
-d '{"input": {"otherserial": "xcvbn"}}' \
1125
'http://path/to/glpi/apirest.php/Computer/10'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1126 1127

< 200 OK
btry's avatar
btry committed
1128
[{"10":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1129 1130 1131 1132


$ curl -X PUT \
-H 'Content-Type: application/json' \
1133 1134
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1135
-d '{"input": {"id": 11,  "otherserial": "abcde"}}' \
1136
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1137 1138

< 200 OK
btry's avatar
btry committed
1139
[{"11":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1140 1141 1142 1143


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

1149
< 207 OK
1150
[{"8":true, "message": ""},{"2":false, "message": "Item not found"}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1151 1152
```

1153
## Delete item(s)
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1154

1155
* **URL**: apirest.php/:itemtype/:id
Remi Collet's avatar
Remi Collet committed
1156
* **Description**: Delete an object existing in GLPI.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1157
* **Method**: DELETE
1158 1159
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
1160
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
1161 1162
* **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
1163
      OR
1164
  * *input* Array of id who need to be deleted. This parameter is passed by payload.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1165 1166 1167

   id parameter has precedence over input payload.

1168
  * *force_purge* (default false): boolean, if the itemtype have a trashbin, you can force purge (delete finally).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1169
                     Optional.
1170
  * *history* (default true): boolean, set to false to disable saving of deletion in global history.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1171
                 Optional.
1172 1173 1174 1175 1176 1177
* **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
1178 1179 1180 1181 1182 1183

Example usage (CURL):

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

btry's avatar
btry committed
1188 1189
< 200 OK
[{"16":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1190 1191 1192

$ curl -X DELETE \
-H 'Content-Type: application/json' \
1193 1194
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1195
-d '{"input": {"id": 11}, "force_purge": true}' \
1196
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1197 1198

< 200 OK
btry's avatar
btry committed
1199
[{"11":true, "message": ""}]
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1200 1201 1202 1203


$ curl -X DELETE \
-H 'Content-Type: application/json' \
1204 1205
-H "Session-Token: 83af7e620c83a50a18d3eac2f6ed05a3ca0bea62" \
-H "App-Token: f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7" \
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1206
-d '{"input": [{"id": 16}, {"id": 17}]}' \
1207
'http://path/to/glpi/apirest.php/Computer/'
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1208 1209

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

1213 1214 1215 1216
## Special cases

### Upload a document file

1217
See [Add item(s)](#add-items) and apply specific instructions below.
1218

1219
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.
1220 1221 1222

Examples usage (CURL):

1223
```bash
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
$ 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": {...}}

```

1238
### Download a document file
1239 1240 1241 1242 1243 1244

* **URL**: apirest.php/Document/:id
* **Description**: Download a document.
* **Method**: GET
* **Parameters**: (Headers)
  * *Session-Token*: session var provided by [initSession](#init-session) endpoint. Mandatory.
1245
  * *App-Token*: authorization string provided by the GLPI API configuration. Optional.
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 1280 1281 1282 1283 1284 1285 1286
  * *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.

1287
## Errors
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1288

1289
### ERROR_ITEM_NOT_FOUND
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1290

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

1293
### ERROR_BAD_ARRAY
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1294 1295 1296

The HTTP body must be an an array of objects.

1297
### ERROR_METHOD_NOT_ALLOWED
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1298 1299 1300

You specified an inexistent or not not allowed resource.

1301
### ERROR_RIGHT_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1302

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

1306
### ERROR_SESSION_TOKEN_INVALID
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1307

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

1311
### ERROR_SESSION_TOKEN_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1312 1313 1314

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

1315
### ERROR_APP_TOKEN_PARAMETERS_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1316 1317 1318

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

Alexandre Delaunay's avatar
Alexandre Delaunay committed
1319 1320 1321 1322
### ERROR_WRONG_APP_TOKEN_PARAMETER

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

1323
### ERROR_NOT_DELETED
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1324 1325 1326

You must mark the item for deletion before actually deleting it

1327
### ERROR_NOT_ALLOWED_IP
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1328

1329
We can't find an active client defined in configuration for your IP.
Remi Collet's avatar
Remi Collet committed
1330
Go to the GLPI Configuration > Setup menu and API tab to check IP access.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1331

1332
### ERROR_LOGIN_PARAMETERS_MISSING
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1333 1334

One of theses parameter(s) is missing:
1335

Alexandre Delaunay's avatar
Alexandre Delaunay committed
1336 1337 1338
* login and password
* or user_token

1339
### ERROR_LOGIN_WITH_CREDENTIALS_DISABLED
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1340

Remi Collet's avatar
Remi Collet committed
1341 1342
The GLPI setup forbid the login with credentials, you must login with your user_token instead.
See your personal preferences page or setup API access in GLPI main interface.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1343

1344
### ERROR_GLPI_LOGIN_USER_TOKEN
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1345

1346
The provided user_token seems invalid.
Remi Collet's avatar
Remi Collet committed
1347
Check your personal preferences page in GLPI main interface.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1348

1349
### ERROR_GLPI_LOGIN
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1350

Remi Collet's avatar
Remi Collet committed
1351 1352
We cannot login you into GLPI. This error is not relative to API but GLPI core.
Check the user administration and the GLPI logs files (in files/_logs directory).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1353

1354
### ERROR_ITEMTYPE_NOT_FOUND_NOR_COMMONDBTM
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1355

Remi Collet's avatar
Remi Collet committed
1356
You asked a inexistent resource (endpoint). It's not a predefined (initSession, getFullSession, etc) nor a GLPI CommonDBTM resources.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1357

1358
See this documentation for predefined ones or [List itemtypes](https://forge.glpi-project.org/apidoc/class-CommonDBTM.html) for available resources
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1359

1360
### ERROR_SQL
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1361

1362
We suspect an SQL error.
Remi Collet's avatar
Remi Collet committed
1363 1364
This error is not relative to API but to GLPI core.
Check the GLPI logs files (in files/_logs directory).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1365

1366
### ERROR_RANGE_EXCEED_TOTAL
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1367 1368 1369

The range parameter you provided is superior to the total count of available data.

1370
### ERROR_GLPI_ADD
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1371

Remi Collet's avatar
Remi Collet committed
1372 1373
We cannot add the object to GLPI. This error is not relative to API but to GLPI core.
Check the GLPI logs files (in files/_logs directory).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1374

1375
### ERROR_GLPI_PARTIAL_ADD
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1376

1377 1378
Some of the object you wanted to add triggers an error.
Maybe a missing field or rights.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1379 1380
You'll find with this error a collection of results.

1381
### ERROR_GLPI_UPDATE
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1382

Remi Collet's avatar
Remi Collet committed
1383 1384
We cannot update the object to GLPI. This error is not relative to API but to GLPI core.
Check the GLPI logs files (in files/_logs directory).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1385

1386
### ERROR_GLPI_PARTIAL_UPDATE
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1387

1388 1389
Some of the object you wanted to update triggers an error.
Maybe a missing field or rights.
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1390 1391
You'll find with this error a collection of results.

1392
### ERROR_GLPI_DELETE
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1393

Remi Collet's avatar
Remi Collet committed
1394 1395
We cannot delete the object to GLPI. This error is not relative to API but to GLPI core.
Check the GLPI logs files (in files/_logs directory).
Alexandre Delaunay's avatar
Alexandre Delaunay committed
1396

1397
### ERROR_GLPI_PARTIAL_DELETE