0.0.2 • Published 6 years ago

node-unmsapi v0.0.2

Weekly downloads
4
License
GPL-2.0
Repository
github
Last release
6 years ago

node-unmsapi

Ubiquiti UNMS API ported to Node.JS

Major features

** Under development

Installation

To install run:

npm install node-unmsapi --save

Usage

All the API are Promises

Direct access to UNMS Controller

If you have a direct access to Ubiquiti UNMS Controller, you could use the following API:

let unms = require('node-unmsapi');
let r = unms({
    baseUrl: 'https://127.0.0.1:443', // The URL of the Unifi Controller
    username: 'ubnt',
    password: 'ubnt',
    // debug: true, // More debug of the API (uses the debug module)
    // debugNet: true // Debug of the network requests (uses request module)
});
r.stat_sessions()
    .then((data) => {
        console.log('Stat sessions', data);
        return r.stat_allusers();
    })
    .then((data) => {
        console.log('AP data', data);
    })
    .catch((err) => {
        console.log('Error', err);
    })

Rebuild Readme.md

If you want to modify the README.md file for any reason (added jsdoc comment somewhere or have done change to README.hbs) please run

npm run readme

API

UnmsAPI(options) ⇒

The main class and the initialization of the UNMS Access

Kind: global function
Returns: this

ParamTypeDescription
optionsobjectthe options during initialization
options.baseUrlstringthe URL where the Unifi controller is. Default https://127.0.0.1:443
options.usernamestringdefault username
options.passwordstringdefault password
options.sitestringdefault site. Default is "default"
options.debugbooleanif the debug log is enabled
options.debugNetbooleanif the debug of the request module is enabled

Example

let UnmsAPI = require('node-unmsapi');
let unifi = UnmsAPI({
   baseUrl: 'https://127.0.0.1:443', // The URL of the Unifi Controller
   username: 'ubnt',
   password: 'ubnt',
   // debug: true, // More debug of the API (uses the debug module)
   // debugNet: true // Debug of the network requests (uses request module)
});

unmsAPI.debugging(enable) ⇒ undefined

Enable or disable the debug of the module

Kind: instance method of UnmsAPI

ParamTypeDescription
enablebooleanEnable or disable the debugging

unmsAPI.netsite(url, jsonParams, headers, method, site) ⇒ Promise

Generic network operation, executing UNMS command under /v2.1//sites/... rest api

Kind: instance method of UnmsAPI

ParamTypeDescription
urlstringThe right part of the URL (/api/s/{site}/ is automatically added)
jsonParamsobjectoptional. Default undefined. If it is defined and it is object, those will be the JSON POST attributes sent to the URL and the the default method is changed from GET to POST
headersobjectoptional. Default {}. HTTP headers that we require to be sent in the request
methodobjectoptional. Default undefined. The HTTP request method. If undefined, then it is automatic. If no jsonParams specified, it will be GET. If jsonParams are specified it will be POST
sitestringoptional. The {site} atribute of the request. If not specified, it is taken from the UnifiAPI init options, where if it is not specified, it is "default"

Example

unifi.netsite('/cmd/stamgr', { cmd: 'authorize-guest', mac: '00:01:02:03:04:05', minutes: 60 }, {}, 'POST', 'default')
    .then(data => console.log('Success', data))
    .catch(error => console.log('Error', error));

unmsAPI.login(username, password) ⇒ Promise

Explicit login to the controller. It is not necessary, as every other method calls implicid login (with the default username and password) before execution

Kind: instance method of UnmsAPI
Returns: Promise - success or failure

ParamTypeDescription
usernamestringThe username
passwordstringThe password

Example

unifi.login(username, password)
    .then(data => console.log('success', data))
    .catch(err => console.log('Error', err))

unmsAPI.logout()

Logout of the controller

Kind: instance method of UnmsAPI
Example

unms.logout()
    .then(() => console.log('Success'))
    .catch(err => console.log('Error', err))

unmsAPI.list_sites() ⇒ Promise

List sites

Kind: instance method of UnmsAPI
Returns: Promise - Promise
Example

unifi.list_sites()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unmsAPI.list_devices() ⇒ Promise

List devices

Kind: instance method of UnmsAPI
Returns: Promise - Promise
Example

unifi.list_devices()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unmsAPI.list_logs(count, which) ⇒ Promise

List logs

Kind: instance method of UnmsAPI
Returns: Promise - Promise

ParamDescription
counthow many to return per page. default is 100000
whichpage to return (default 1)

Example

unifi.list_logs()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unmsAPI.list_outages(count, which) ⇒ Promise

List outages

Kind: instance method of UnmsAPI
Returns: Promise - Promise

ParamDescription
counthow many to return per page. default is 100000
whichpage to return (default 1)

Example

unifi.list_outages()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unmsAPI.list_settings() ⇒ Promise

List settings

Kind: instance method of UnmsAPI
Returns: Promise - Promise
Example

unifi.list_outages()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unmsAPI.keepalive() ⇒ Promise

Do keepalive

Kind: instance method of UnmsAPI
Returns: Promise - Promise
Example

unifi.list_outages()
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))