Usage

Here we present you the code examples of the library per API Method, we created these examples using functions with promises as it is easier to detect where occurred an error in the execution of your code.

Examples

const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.killSession()
            .then((res2) => {
                console.log(res2)
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getMyProfiles()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getActiveProfile()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getMyProfiles()
            .then((res2) => {
                client.changeActiveProfile(res2.data[0].id)
                    .then((res3) => {
                        console.log(res3)
                        client.killSession()
                            .catch((err4) => {
                                console.log(err4)
                            })
                    })
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getMyEntities()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getActiveEntities()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        console.log(res)
        client.changeActiveEntities(null, true)
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getFullSession()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })

const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getGlpiConfig()
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

let query = new GetItemQuery()
query.with_networkports = true
query.with_infocoms = true
query.with_contracts = true
query.with_documents = true

client.initSessionByCredentials(config.user.name, config.user.password)
    .then((res) => {
        client.getItem(itemtype.User, 40, query.createQueryObject())
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
onst client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getAllItems(itemtype.UserEmail)
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })

const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.getSubItems(itemtype.User, 37, itemtype.UserEmail)
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.addItem(itemtype.UserEmail, {users_id: 37, email: 'example@email.com'})
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.addItem(itemtype.UserEmail, {users_id: 37, email: 'example@email.com'})
            .then((res2) => {
                console.log(res2)
                client.updateItem(itemtype.UserEmail, null, {id: res2.data.id, users_id: 37, email: 'example2@email.com'})
                    .then((res3) => {
                        console.log(res3)
                        client.killSession()
                            .catch((err4) => {
                                console.log(err4)
                            })
                    })
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
    .then((res) => {
        client.deleteItem(itemtype.UserEmail, null, {id: 162, users_id: 37, email: 'example@email.com'})
            .then((res2) => {
                console.log(res2)
                client.killSession()
                    .catch((err3) => {
                        console.log(err3)
                    })
            })
            .catch((err2) => {
                console.log(err2)
            })
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.recoveryPassword(config.user.email)
    .then((res) => {
        console.log(res)
    })
    .catch((err) => {
        console.log(err)
    })
const client = new GlpiRestClient(config.apirest)

client.resetPassword(config.user.email, 'e446c1ff23d7ba097cc7104edaee5139ddf610be', 12345678)
    .then((res) => {
        console.log(res)
    })
    .catch((err) => {
        console.log(err)
    })

For more information about the functions check our Code Documentation section