Usage

Here we present you the code examples of the library per API Method, as we do our best to provide the most up to date technologies, we created the examples using Async - Await functions as it is the latest form to implement the asynchronous methods with Node, as it is you may not be able to use it properly unless your Node.js environment is up to date.

Examples

(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        // await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken);
        const Session = await client.killSession()
        console.log(Session)
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const MyProfiles = await client.getMyProfiles()
        console.log(MyProfiles)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const ActiveProfile = await client.getActiveProfile()
        console.log(ActiveProfile)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const MyProfiles = await client.getMyProfiles()
        const ChangeActiveProfile = await client.changeActiveProfile(MyProfiles.data[0].id)
        console.log(ChangeActiveProfile)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const MyEntities = await client.getMyEntities()
        console.log(MyEntities)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const ActiveEntities = await client.getActiveEntities()
        console.log(ActiveEntities)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const ChangeActiveEntities = await client.changeActiveEntities(null, true)
        console.log(ChangeActiveEntities)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const FullSession = await client.getFullSession()
        console.log(FullSession)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const GlpiConfig = await client.getGlpiConfig()
        console.log(GlpiConfig)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        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
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const Item = await client.getItem(itemtype.User, 40, query.createQueryObject())
        console.log(Item)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const AllItems = await client.getAllItems(itemtype.UserEmail)
        console.log(AllItems)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const SubItems = await client.getSubItems(itemtype.User, 37, itemtype.UserEmail)
        console.log(SubItems)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const NewItem = await client.addItems(itemtype.UserEmail, [{users_id: 40, email: 'example@email.com'}, {users_id: 40, email: 'example2@email.com'}])
        console.log(NewItem)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const Item = await client.updateItems(itemtype.UserEmail, null, [{id: 169, email: 'exam@email.com'}, {id: 170, email: 'exam2@email.com'}])
        console.log(Item)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        await client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
        const ItemDelete = await client.deleteItems(itemtype.UserEmail, null, [{id: 167}, {id: 168}])
        console.log(ItemDelete)
        await client.killSession()
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        const recoveryPassword = await client.recoveryPassword(config.user.email)
        console.log(recoveryPassword)
    } catch (err) {
        console.log(err)
    }
})()
(async () => {
    try {
        const client = new GlpiRestClient(config.apirest)
        const resetPassword = await client.resetPassword(config.user.email, 'yourToken', 'yourNewPassword')
        console.log(resetPassword)
    } catch (err) {
        console.log(err)
    }
})()

For more information about the functions check our Code Documentation section