# GLPI-API

Node module for GLPI REST API

## Installation

    $ npm install --save glpi-api

## Usage

### Configuration

    const GlpiApi = require('glpi-api');

    // Config with user_token
    const config = {
      app_token  : 'AHBIwc4M21Q8yaOzrluxojHJRvHTF6gteAlDBaFW',
      apiurl     : 'https://myglpi.com/apirest.php',
      user_token : 'tt5jyPvv311OzjmrJMNh2Gqgu5ovOOy7saE2fI5ha',
    };

    // or

    // Config with basic auth
    const config = {
      app_token : 'AHBIwc4M21Q8yaOzrluxojHJRvHTF6gteAlDBaFW',
      apiurl     : 'https://myglpi.com/apirest.php',
      auth      : {
        username : 'glpi',
        password : 'secret',
      },
    };

    const glpi = new GlpiApi(config);

### Examples

#### Get a ticket

    glpi.initSession()
    .then(() => glpi.getItem('Ticket', 123456))
    .then((ticket) => {
      // Do what you want with your ticket
    })
    .catch((err) => {
      // Manage error
    })
    .then(() => glpi.killSession());

#### Close a ticket

    glpi.initSession()
    .then(() => glpi.updateItems('Ticket', ticket.id))
    .catch((err) => {
      // Manage error
    })
    .then(() => glpi.killSession());

## Test

Tests are only available for cloned repository

    $ npm test

## Versioning

I use SemVer for versioning.

## Authors

- Martial Séron - Initial work - MartialSeron

## License

This project is licensed under the MIT License - see the LICENSE.md file for details