node-unmsapi

0.0.2 • Public • Published

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

Param Type Description
options object the options during initialization
options.baseUrl string the URL where the Unifi controller is. Default https://127.0.0.1:443
options.username string default username
options.password string default password
options.site string default site. Default is "default"
options.debug boolean if the debug log is enabled
options.debugNet boolean if 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

Param Type Description
enable boolean Enable 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

Param Type Description
url string The right part of the URL (/api/s/{site}/ is automatically added)
jsonParams object optional. 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
headers object optional. Default {}. HTTP headers that we require to be sent in the request
method object optional. 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
site string optional. 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

Param Type Description
username string The username
password string The 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

Param Description
count how many to return per page. default is 100000
which page 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

Param Description
count how many to return per page. default is 100000
which page 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))

Readme

Keywords

Package Sidebar

Install

npm i node-unmsapi

Weekly Downloads

0

Version

0.0.2

License

GPL-2.0

Unpacked Size

63.3 kB

Total Files

7

Last publish

Collaborators

  • delian