2.0.0 • Published 3 years ago
ninja-rmm-node v2.0.0
ninja-rmm-node
Installation
npm install ninja-rmm-nodeUsage
CommonJS
const NinjaRMM = require('ninja-rmm-node')ESM
import NinjaRMM from 'ninja-rmm-node'Options
For headless (API/M2M), use client_credentials grantType. Defaults to client_credentials.
const options = {
grantType: 'client_credentials',
region: 'na',
clientSecret,
clientId,
scope: 'monitoring management control',
}
const ninja = new NinjaRMM(options)For interactive login, use authorization_code. The default browser will open to prompt for user authentication. Note: this will not work if trying to run this module in the browser.
const options = {
grantType: 'authorization_code',
region: 'na',
clientSecret,
clientId,
scope: 'monitoring management control offline_access',
}If you've previously requested a refresh_token with offline_access scope, use grantType refresh_token:
const options = {
grantType: 'refresh_token',
region: 'na',
clientSecret,
clientId,
refreshToken: 'mytoken'
}Usage
See documentation for a list of endpoints and parameters.
Using async/await:
/**
* @param {string} path
* @param {string} [method]
* @param {object} [params]
* @param {object} [data] if method is POST or PUT, this is put in the body
* @returns {Promise<*>}
*/
const result = await ninja.request({path: '/api/v2/organizations'})Or with promises:
ninja.request(options)
.then(result => {
// use result
})Generate a token for use elsewhere with these static methods:
const token = await NinjaRMM.generateTokenClientCredentials({clientSecret, clientId, scope, region})
const token = await NinjaRMM.generateTokenRefresh({clientSecret, clientId, region, refreshToken})
const token = await NinjaRMM.generateTokenAuthorizationCode({clientSecret, clientId, region, scope})