Constructor
new Glpi(settings)
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
|
Methods
_getAuth() → {object}
Return the appropriate string for authentication
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
settings.auth |
Object | 2 parameters to login with user authentication Properties
|
Returns:
- Type
- object
_parseContentRange(headers) → {object}
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}
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
|
Returns:
- Type
- object
_validateItemType(itemType) → {boolean}
Validate if itemType is accepted by GLPI
Parameters:
| Name | Type | Description |
|---|---|---|
itemType |
string | itemType requested |
Returns:
- Type
- boolean
addCustomItemTypes(customItemTypes) → {undefined}
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}
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}
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}
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}
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
|
Returns:
- Type
- Promise
download(documentId) → {Promise}
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}
Return active entities of current logged user.
Returns:
- Type
- Promise
getActiveProfile() → {Promise}
Return the current active profile.
Returns:
- Type
- Promise
getFullSession() → {Promise}
Return the current php $_SESSION.
Returns:
- Type
- Promise
getItem(itemType, id, optsopt) → {Promise}
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
|
Returns:
- Type
- Promise
getItems(itemType, optsopt) → {Promise}
Return a collection of rows of the itemtype.
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
itemType |
string | itemtype requested |
||||||||||||||||||||||||||||||||||||||||||||||
opts |
object |
<optional> |
Properties
|
Returns:
- Type
- Promise
getMultipleItems(optsopt) → {Promise}
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
|
Returns:
- Type
- Promise
getMyEntities() → {Promise}
Return all the possible entities of the current logged user (and for current active profile).
Returns:
- Type
- Promise
getMyProfiles() → {Promise}
Return all the profiles associated to logged user.
Returns:
- Type
- Promise
getSubItems(itemType, id, subItemType, optsopt) → {Promise}
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
|
Returns:
- Type
- Promise
initSession() → {Promise}
Request a session token to use other api endpoints.
Returns:
- Type
- Promise
killSession() → {Promise}
Destroy a session identified by a session token.
Returns:
- Type
- Promise
listSearchOptions(itemType, rawopt) → {Promise}
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}
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}
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
|
Returns:
- Type
- Promise
updateItems(itemType, idopt, input) → {Promise}
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}
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