# Glpi

Class to manage access to GLPI via REST API

## Constructor

#### new Glpi(settings)

Source:
  - glpi.js, line 66

Create a Glpi object

Usage :

    const Glpi = require('glpi-api');
    const glpi = new Glpi({
      apiurl     : 'http://glpi.myserver.com/apirest.php',
      user_token : 'q56hqkniwot8wntb3z1qarka5atf365taaa2uyjrn',
      app_token  : 'f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7',
    });

    // or

    const glpi = new Glpi({
      apiurl     : 'http://glpi.myserver.com/apirest.php',
      app_token  : 'f7g3csp8mgatg5ebc5elnazakw20i9fyev1qopya7',
      auth       : {
        username : 'glpi',
        password : 'glpi',
      }
    });

##### Parameters:

Name | Type | Description
--- | --- | ---

`settings`

Object

###### Properties

Name | Type | Description
--- | --- | ---
`user_token` | Object | Token used for user token authentication

`auth`

Object

2 parameters to login with user authentication

###### Properties

Name | Type | Description
--- | --- | ---
`username` | Object | username parameter used for user authentication
`password` | Object | password parameter used for user authentication

`app_token` | Object | Authorization string provided by the GLPI api configuration
`apiurl` | Object | URL of the apirest.php file

### Methods

#### _getAuth() → {object}

Source:
  - glpi.js, line 122

Return the appropriate string for authentication

##### Parameters:

Name | Type | Description
--- | --- | ---

`settings.auth`

Object

2 parameters to login with user authentication

###### Properties

Name | Type | Description
--- | --- | ---
`username` | Object | username parameter used for user authentication
`password` | Object | password parameter used for user authentication

##### Returns:

Type
  object

#### _parseContentRange(headers) → {object}

Source:
  - glpi.js, line 220

Extract min, max and total from Content-Range header

##### Parameters:

Name | Type | Description
--- | --- | ---
`headers` | object | key/value object of HTTP headers

##### Returns:

Type
  object

#### _request(method, endpoint, options) → {object}

Source:
  - glpi.js, line 143

Send HTTP requests

##### Parameters:

Name | Type | Description
--- | --- | ---
`method` | string | HTTP method to use for the request. Only GET, POST, PUT and DELETE are accepted, throws an InvalidHTTPMethodError otherwise.
`endpoint` | string | API endpoint

`options`

object

###### Properties

Name | Type | Description
--- | --- | ---
`headers` | object | HTTP headers to add to the request
`query` | object | URL query string to add to the request

##### Returns:

Type
  object

#### _validateItemType(itemType) → {boolean}

Source:
  - glpi.js, line 203

Validate if itemType is accepted by GLPI

##### Parameters:

Name | Type | Description
--- | --- | ---
`itemType` | string | itemType requested

##### Returns:

Type
  boolean

#### addCustomItemTypes(customItemTypes) → {undefined}

Source:
  - glpi.js, line 105

Add one or more custom itemTypes to the valid itemTypes list

##### Parameters:

Name | Type | Description
--- | --- | ---
`customItemTypes` | string | array | String or array of string of itemType to add to the valid itemTypes list

##### Returns:

Type
  undefined

#### addItems(itemType, input) → {Promise}

Source:
  - glpi.js, line 706

Add an object (or multiple objects) into GLPI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`itemType` | string | itemType requested
`input` | object | Array.<object> | an object with fields of itemtype to be inserted. You can add several items in one action by passing an array of objects. Mandatory.

##### Returns:

Type
  Promise

#### changeActiveEntities(profiles_id) → {Promise}

Source:
  - glpi.js, line 374

Change active profile to the profiles_id one. See getMyProfiles endpoint for possible profiles.

##### Parameters:

Name | Type | Description
--- | --- | ---
`profiles_id` | integer | ID of the new active profile.

##### Returns:

Type
  Promise

#### changeActiveProfile(profiles_id) → {Promise}

Source:
  - glpi.js, line 332

Change active profile to the profiles_id one. See ${getMyProfiles} endpoint for possible profiles.

##### Parameters:

Name | Type | Description
--- | --- | ---
`profiles_id` | integer | ID of the new active profile.

##### Returns:

Type
  Promise

#### deleteItems(itemType, idopt, input, optsopt) → {Promise}

Source:
  - glpi.js, line 775

Delete an object existing in GLPI.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string |  | itemType requested
`id` | string | <optional> | the unique identifier of the itemtype passed in URL. You could skip this parameter by passing it in the input payload.
`input` | object | Array.<object> |  | Array of id who need to be deleted.

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`force_purge` | object | <optional> | `false` | boolean, if the itemtype have a dustbin, you can force purge (delete finally). Optional.
`history` | object | <optional> | `true` | boolean, set to false to disable saving of deletion in global history. Optional.

##### Returns:

Type
  Promise

#### download(documentId) → {Promise}

Source:
  - glpi.js, line 861

Download a document from GLPI

##### Parameters:

Name | Type | Description
--- | --- | ---
`documentId` | string | number | unique identifier of the itemtype passed in the URL.

##### Returns:

Type
  Promise

#### getActiveEntities() → {Promise}

Source:
  - glpi.js, line 359

Return active entities of current logged user.

##### Returns:

Type
  Promise

#### getActiveProfile() → {Promise}

Source:
  - glpi.js, line 317

Return the current active profile.

##### Returns:

Type
  Promise

#### getFullSession() → {Promise}

Source:
  - glpi.js, line 387

Return the current php $_SESSION.

##### Returns:

Type
  Promise

#### getItem(itemType, id, optsopt) → {Promise}

Source:
  - glpi.js, line 419

Return the instance fields of itemtype identified by id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string |  | itemtype requested
`id` | string |  | unique identifier of the itemtype. Mandatory.

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`expand_dropdowns` | boolean | <optional> | `false` | show dropdown name instead of id.
`get_hateoas` | boolean | <optional> | `true` | Show relations of the item in a links attribute.
`get_sha1` | boolean | <optional> | `false` | Get a sha1 signature instead of the full answer.
`with_devices` | boolean | <optional> | `false` | Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components.
`with_disks` | boolean | <optional> | `false` | Only for Computer, retrieve the associated file-systems.
`with_softwares` | boolean | <optional> | `false` | Only for Computer, retrieve the associated software's installations.
`with_connections` | boolean | <optional> | `false` | Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optional.
`with_networkports` | boolean | <optional> | `false` | Retrieve all network's connections and advanced network's informations.
`with_infocoms` | boolean | <optional> | `false` | Retrieve financial and administrative informations.
`with_contracts` | boolean | <optional> | `false` | Retrieve associated contracts.
`with_documents` | boolean | <optional> | `false` | Retrieve associated external documents.
`with_tickets` | boolean | <optional> | `false` | Retrieve associated itil tickets.
`with_problems` | boolean | <optional> | `false` | Retrieve associated itil problems.
`with_changes` | boolean | <optional> | `false` | Retrieve associated itil changes.
`with_notes` | boolean | <optional> | `false` | Retrieve Notes.
`with_logs` | boolean | <optional> | `false` | Retrieve historical.

##### Returns:

Type
  Promise

#### getItems(itemType, optsopt) → {Promise}

Source:
  - glpi.js, line 465

Return a collection of rows of the itemtype.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string |  | itemtype requested

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`expand_dropdowns` | boolean | <optional> | `false` | show dropdown name instead of id.
`get_hateoas` | boolean | <optional> | `true` | Show relation of item in a links attribute.
`only_id` | boolean | <optional> | `false` | keep only id keys in returned data.
`range` | string | <optional> | `0-50` | a string with a couple of number for start and end of pagination separated by a '-'. Ex: 150-200.
`sort` | string | <optional> | `id` | id of the searchoption to sort by.
`order` | string | <optional> | `DESC` | ASC - Ascending sort / DESC Descending sort.
`searchText` | string | <optional> |  | array of filters to pass on the query (with key = field and value the text to search)
`is_deleted` | boolean | <optional> | `false` | Return deleted element.

##### Returns:

Type
  Promise

#### getMultipleItems(optsopt) → {Promise}

Source:
  - glpi.js, line 579

Virtually call Get an item for each line in input. So, you can have a ticket and a user in the same query.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---

`items`

Array.<object>

items to retrieve. Mandatory. Each line of this array should contains two keys: `itemtype`and `items_id`

###### Properties

Name | Type | Description
--- | --- | ---
`itemtype` | string | itemtype requested
`items_id` | string | unique identifier of the itemtype

`expand_dropdowns` | boolean | <optional> | `false` | show dropdown name instead of id. Optional.
`get_hateoas` | boolean | <optional> | `true` | Show relations of the item in a links attribute. Optional.
`get_sha1` | boolean | <optional> | `false` | Get a sha1 signature instead of the full answer. Optional.
`with_devices` | boolean | <optional> | `false` | Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components. Optional.
`with_disks` | boolean | <optional> | `false` | Only for Computer, retrieve the associated file-systems. Optional.
`with_softwares` | boolean | <optional> | `false` | Only for Computer, retrieve the associated software's installations. Optional.
`with_connections` | boolean | <optional> | `false` | Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optional.
`with_networkports` | boolean | <optional> | `false` | Retrieve all network's connections and advanced network's informations. Optional.
`with_infocoms` | boolean | <optional> | `false` | Retrieve financial and administrative informations. Optional.
`with_contracts` | boolean | <optional> | `false` | Retrieve associated contracts. Optional.
`with_documents` | boolean | <optional> | `false` | Retrieve associated external documents. Optional.
`with_tickets` | boolean | <optional> | `false` | Retrieve associated itil tickets. Optional.
`with_problems` | boolean | <optional> | `false` | Retrieve associated itil problems. Optional.
`with_changes` | boolean | <optional> | `false` | Retrieve associated itil changes. Optional.
`with_notes` | boolean | <optional> | `false` | Retrieve Notes. Optional.
`with_logs` | boolean | <optional> | `false` | Retrieve historical. Optional.

##### Returns:

Type
  Promise

#### getMyEntities() → {Promise}

Source:
  - glpi.js, line 345

Return all the possible entities of the current logged user (and for current active profile).

##### Returns:

Type
  Promise

#### getMyProfiles() → {Promise}

Source:
  - glpi.js, line 305

Return all the profiles associated to logged user.

##### Returns:

Type
  Promise

#### getSubItems(itemType, id, subItemType, optsopt) → {Promise}

Source:
  - glpi.js, line 502

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string | object |  | parent itemtype provided. If Object, id must not be provided
`id` | string |  | unique identifier of the itemtype. Mandatory if itemType is a string.
`subItemType` | string |  | subItemType requested

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`expand_dropdowns` | boolean | <optional> | `false` | show dropdown name instead of id. Optional.
`get_hateoas` | boolean | <optional> | `true` | Show relation of item in a links attribute. Optional.
`only_id` | boolean | <optional> | `false` | keep only id keys in returned data. Optional.
`range` | string | <optional> | `0-50` | a string with a couple of number for start and end of pagination separated by a '-'. Ex: 150-200. Optional.
`sort` | string | <optional> | `id` | id of the searchoption to sort by. Optional.
`order` | string | <optional> | `DESC` | ASC - Ascending sort / DESC Descending sort. Optional.

##### Returns:

Type
  Promise

#### initSession() → {Promise}

Source:
  - glpi.js, line 237

Request a session token to use other api endpoints.

##### Returns:

Type
  Promise

#### killSession() → {Promise}

Source:
  - glpi.js, line 264

Destroy a session identified by a session token.

##### Returns:

Type
  Promise

#### listSearchOptions(itemType, rawopt) → {Promise}

Source:
  - glpi.js, line 620

List the searchoptions of provided itemtype. To use with Search items.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`itemType` | string |  |  | itemType requested
`raw` | boolean | <optional> | `false` | return searchoption uncleaned if true (as provided by core)

##### Returns:

Type
  Promise

#### lostPassword(email, password_forget_token, password) → {Promise}

Source:
  - glpi.js, line 286

Sends a notification to the user to reset his password. Reset the password if `password_forget_token` and `password` are provided

##### Parameters:

Name | Type | Description
--- | --- | ---
`email` | string | email address of the user to recover. Mandatory.
`password_forget_token` | string | reset token. Mandatory to reset password
`password` | string | the new password for the user. Mandatory to reset password

##### Returns:

Type
  Promise

#### search(itemType, optsopt) → {Promise}

Source:
  - glpi.js, line 674

Expose the GLPI searchEngine and combine criteria to retrieve a list of elements of specified itemtype.

Note: you can use 'AllAssets' itemtype to retrieve a combination of all asset's types.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string |  | itemType requested

`opts`

object

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---

`criteria`

Array.<object>

array of criterion objects to filter search. Optional. Each criterion object must provide :

- link: (optional for 1st element) logical operator in [AND, OR, AND NOT, AND NOT].
- field: id of the searchoption.
- searchtype: type of search in [contains, equals, notequals, lessthan, morethan, under, notunder].
- value: the value to search.

###### Properties

Name | Type | Description
--- | --- | ---
`link` | string | (optional for 1st element) logical operator in [AND, OR, AND NOT, AND NOT].
`field` | string | id of the searchoption.
`searchtype` | string | type of search in [contains, equals, notequals, lessthan, morethan, under, notunder].
`value` | string | the value to search.

`metacriteria`

Array.<object>

array of meta-criterion objects to filter search. Optional. A meta search is a link with another itemtype (ex: Computer with softwares). Each meta-criterion object must provide:

- link: logical operator in [AND, OR, AND NOT, AND NOT]. Mandatory.
- itemtype : second itemtype to link.
- field: id of the searchoption.
- searchtype: type of search in [contains, equals, notequals, lessthan, morethan, under, notunder].
- value: the value to search.

###### Properties

Name | Type | Description
--- | --- | ---
`link` | string | logical operator in [AND, OR, AND NOT, AND NOT]. Mandatory.
`itemtype` | string | second itemtype to link.
`field` | string | id of the searchoption.
`searchtype` | string | type of search in [contains, equals, notequals, lessthan, morethan, under, notunder].
`value` | string | the value to search.

`sort` | string | <optional> | `id` | id of the searchoption to sort by. Optional.
`order` | object | <optional> | `DESC` | ASC - Ascending sort / DESC Descending sort. Optional.
`range` | object | <optional> | `0-50` | a string with a couple of number for start and end of pagination separated by a '-'. Ex: 150-200. Optional.
`forcedisplay` | array |  |  | array of columns to display (default empty = use display preferences and searched criteria). Some columns will be always presents (1: id, 2: name, 80: Entity). Optional.
`rawdata` | object | <optional> | `false` | a boolean for displaying raws data of the Search engine of glpi (like SQL request, full searchoptions, etc)
`withindexes` | object | <optional> | `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). So, we provide arrays to guarantying sorted rows.
`uid_cols` | object | <optional> | `false` | a boolean to identify cols by the 'uniqid' of the searchoptions instead of a numeric value (see List searchOptions and 'uid' field)
`giveItems` | object | <optional> | `false` | a boolean to retrieve the data with the html parsed from core, new data are provided in data_html key.

##### Returns:

Type
  Promise

#### updateItems(itemType, idopt, input) → {Promise}

Source:
  - glpi.js, line 731

Update an object (or multiple objects) existing in GLPI.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemType` | string |  | itemType requested
`id` | string | <optional> | the unique identifier of the itemtype passed in URL. You could skip this parameter by passing it in the input payload.
`input` | object | Array.<object> |  | an object with fields of itemtype to be inserted. You can add several items in one action by passing an array of objects. Mandatory.

##### Returns:

Type
  Promise

#### upload(filePath, descriptionopt) → {Promise}

Source:
  - glpi.js, line 818

Upload a document to GLPI

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`filePath` | string |  | Absolute path to the file to upload
`description` | string | <optional> | Description to add to document

##### Returns:

Type
  Promise