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 = ;let unifi = ;
- UnmsAPI(options) ⇒
- .debugging(enable) ⇒
undefined
- .netsite(url, jsonParams, headers, method, site) ⇒
Promise
- .login(username, password) ⇒
Promise
- .logout()
- .list_sites() ⇒
Promise
- .list_devices() ⇒
Promise
- .list_logs(count, which) ⇒
Promise
- .list_outages(count, which) ⇒
Promise
- .list_settings() ⇒
Promise
- .keepalive() ⇒
Promise
- .debugging(enable) ⇒
undefined
unmsAPI.debugging(enable) ⇒ Enable or disable the debug of the module
Kind: instance method of UnmsAPI
Param | Type | Description |
---|---|---|
enable | boolean |
Enable or disable the debugging |
Promise
unmsAPI.netsite(url, jsonParams, headers, method, site) ⇒ 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 ;
Promise
unmsAPI.login(username, password) ⇒ 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
unmsAPI.logout()
Logout of the controller
Kind: instance method of UnmsAPI
Example
unms
Promise
unmsAPI.list_sites() ⇒ List sites
Kind: instance method of UnmsAPI
Returns: Promise
- Promise
Example
unifi
Promise
unmsAPI.list_devices() ⇒ List devices
Kind: instance method of UnmsAPI
Returns: Promise
- Promise
Example
unifi
Promise
unmsAPI.list_logs(count, which) ⇒ 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
Promise
unmsAPI.list_outages(count, which) ⇒ 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
Promise
unmsAPI.list_settings() ⇒ List settings
Kind: instance method of UnmsAPI
Returns: Promise
- Promise
Example
unifi
Promise
unmsAPI.keepalive() ⇒ Do keepalive
Kind: instance method of UnmsAPI
Returns: Promise
- Promise
Example
unifi