0.0.54 • Published 4 years ago

node-unifiapi v0.0.54

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

node-unifiapi

UniFi API ported to Node.JS

This library is a rewrite of the PHP based UniFi-API-Browser written in JavaScript for Node-JS.

It is mimicking the UniFi-API-Browser API calls (the same commands the same effects) for Ubiquiti Unifi Controller versions 4 and 5 with addition of few more generic calls.

Major features

  • Implements the major (if not all) calls to the REST API of the Ubiquiti for Unifi Controller
  • Supports WebRTC (over the Ubiquiti Unifi Cloud) protocol. If you have your devices registerred in the Unifi Cloud you can access them and execute the same REST API calls over WebRTC
  • Supports SSH access to the devices that support it (mostly UAP) over WebRTC
  • Supports Plug-in replacement for the WebRTC module (tested with electron-webrtc) in case wrtc doesn't work for you for some reason

Warning

Quite unstable mostly due to the instability of the WebRTC implementation in Node.JS. Also highly incompleted and untested. Any help appreciated!

Installation

To install run:

npm install node-unifiapi --save

The installation DOES NOT depend on the Node's wrtc module anymore. If you want to use the WebRTC functionality (Unifi cloudapi and SSH tunnels to device) you have to install webrtc module, and if this module is not node-webrtc you have to explicitly specify it according to the documentation.

To install node-webrtc do:

npm install node-webrtc --save

The install requirements for node-webrtc are visible here node-webrtc. Please consult with the installation requirements of this module in order to be able to install it.

XOpenDisplay Error

A frequent error caused by node-webrtc module is the one defined in issue #281

node: symbol lookup error: [local-path]/build/wrtc/v0.0.61/Release/node-v47-linux-x64/wrtc.node: undefined symbol: XOpenDisplay

It happens mostly on Linux, almost exquisively if the Linux have X11 subsystem, although it is not caused directly by it (but a bad linking). The easiest method to avoid it is to use non desktop (non X11 based) Linux distribution, like Ubuntu Server. We all hope that in version 0.0.62 of the node-webrtc module this issue will be fixed.

Segmentation errors

Again, the node-wrtc module is quite unstable sometimes. I find it best working on OSX or Linux (Linux Server, without X11 libraries) with the prebuilt binary images (which for the moment requires node version 6.9 maximum for Linux). The problem with this instability seems to be well known to the wrtc community but I cannot predict when it will be fixed.

However, the unifiapi module uses the standart webrtc api, so it could work with any webrtc module with the standard api.

Following is an example with electron-webrtc module:

npm install electron-webrtc

And then a test (example) code:

let cloud = require('node-unifiapi/cloudapi');
let wrtc = require('electron-webrtc')({ headless: true });

let r = cloud({ device-id: 'xxx-xxx-xx-xx-xx-xx', username: 'myuser', password: 'mypass', webrtc: wrtc, waiter: 1000 }).api;

r.stat_sessions().then(data => console.log('Success', data).catch(err => console.log('Error', err);

The waiter property sets delay between every command sent to the webrtc in ms. I found electron-webrtc working better, if there is at least 500ms delay between the calls.

Test from CLI

There is a sister project available here https://github.com/delian/unificli which provides CLI tool where all (or most) of the calls of this API are exposed as REPL CLI commands one could use to test.

Usage

All the API are Promises

Direct access to Ubiquiti Unifi Controller

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

let unifi = require('node-unifiapi');
let r = unifi({
    baseUrl: 'https://127.0.0.1:8443', // 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);
    })

Access via Unifi Cloud and WebRTC

If you have to access the Unifi Controller if it is behind NAT and you need to use WebRTC to access it or known only via Unifi Cloud:

let cloud = require('node-unifiapi/cloudapi');
let r = cloud({
    deviceId: '801bb78e12c80000000001a22aea000000000203c905000000066660aaaa', // The cloud id of the device
    username: 'clouduser',
    password: 'cloudpass',
    // debug: true, // More debug of the API (uses the debug module)
    // debugNet: true // Debug of the network requests
});
r.api.stat_sessions()
    .then((data) => {
        console.log('Stat sessions', data);
        return r.api.stat_allusers();
    })
    .then((data) => {
        console.log('AP data', data);
    })
    .catch((err) => {
        console.log('Error', err);
    })

Be careful - when we use the cloud access all the Unifi calls are available under the .api property, to not confuse with the API calls that are related to the cloud management itself.

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

Functions

UnifiAPI(options) ⇒

The main class and the initialization of the Unifi 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:8443
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 UnifiAPI = require('node-unifiapi');
let unifi = UnifiAPI({
   baseUrl: 'https://127.0.0.1:8443', // 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)
});

unifiAPI.debugging(enable) ⇒ undefined

Enable or disable the debug of the module

Kind: instance method of UnifiAPI

ParamTypeDescription
enablebooleanEnable or disable the debugging

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

Generic network operation, executing Ubiquiti command under /api/s/{site}/... rest api

Kind: instance method of UnifiAPI

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));

unifiAPI.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 UnifiAPI
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))

unifiAPI.logout()

Logout of the controller

Kind: instance method of UnifiAPI
Example

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

unifiAPI.authorize_guest(mac, minutes, up, down, mbytes, apmac, site) ⇒ Promise

Authorize guest by a MAC address

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringmac address of the guest - mandatory
minutesstringminutes for the authorization - optional, default 60 min
upstringupstream bandwidth in Kbps. Default no limit
downstringdownstream bandwidth in Kbps. Default no _limit
mbytesstringdownload limit in Mbytes. Default no limit
apmacstringto which mac address the authorization belongs. Default any
sitestringto which site (Ubiquiti) the command will be applied if it is different than the default

Example

unifi.authorize_guest('01:02:aa:bb:cc')
    .then(data => console.log('Successful authorization'))
    .catch(err => console.log('Error', err))

unifiAPI.unauthorize_guest(mac, site) ⇒ Promise

De-authorize guest by a MAC address

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringthe mac address
sitesiteUbiquiti site, if different from default - optional

Example

unifi.unauthorize_guest('00:01:02:03:aa:bb')
    .then(done => console.log('Success', done))
    .catch(err => console.log('Error', err))

unifiAPI.kick_sta(mac, site) ⇒ Promise

Kick a client (station) of the network. This will disconnect a wireless user if it is connected

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
sitestringUbiquiti site, if different from default - optional

Example

unifi.kick_sta('00:00:11:22:33:44')
    .then(done => console.log('Success', done))
    .catch(err => console.log('Error', err))

unifiAPI.terminate_guest(id, site) ⇒ Promise

Terminate access of a Guest (logged in via Guest Authorization). It kicks it out of the wireless and authroization

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
idstringthe ID of the guest that have to be kicked out
sitestringUbiquiti site, if different from default - optional

Example

unifi.terminate_guest('aa01af0133d334d77d')
    .this(done => console.log('Success', done))
    .catch(err => console.log('Error', err))

unifiAPI.block_sta(mac, site) ⇒ Promise

Block station of the network

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
sitestringUbiquiti site, if different from default - optional

Example

unifi.block_sta('00:01:02:03:04:05')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error', err))

unifiAPI.unblock_sta(mac, site) ⇒ Promise

Unblock station of the network

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
sitestringUbiquiti site, if different from default - optional

Example

unifi.block_sta('00:01:02:03:04:05')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error', err))

unifiAPI.set_sta_note(user, note, site) ⇒ Promise

Set or remove Note to a station

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
userstringUser ID
notestringNote
sitestringUbiquiti site, if different from default - optional

Example

unifi.set_sta_note('aabbaa0102aa03aa3322','Test note')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

Example

unifi.set_sta_note('aabbaa0102aa03aa3322','') // remove note
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.set_sta_name(user, name, site) ⇒ Promise

Set or remove Name to a station

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
userstringUser ID
namestringName
sitestringUbiquiti site, if different from default - optional

Example

unifi.set_sta_name('aabbaa0102aa03aa3322','Central Access Point')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

Example

unifi.set_sta_name('aabbaa0102aa03aa3322','') // remove name
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.stat_sessions(start, end, type, site) ⇒ Promise

List client sessions

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
startnumberStart time in Unix Timestamp - Optional. Default 7 days ago
endnumberEnd time in Unix timestamp - Optional. Default - now
typestringSessions type. Optional. Default all
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_daily_site(start, end, attrs, site) ⇒ Promise

List daily site statistics

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
startnumberStart time in Unix Timestamp - Optional. Default 7 days ago
endnumberEnd time in Unix timestamp - Optional. Default - now
attrsarrayWhat attributes we are quering for. Optional. Default 'bytes', 'wan-tx_bytes', 'wan-rx_bytes', 'wlan_bytes', 'num_sta', 'lan-num_sta', 'wlan-num_sta', 'time'
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_hourly_site(start, end, attrs, site) ⇒ Promise

List hourly site statistics

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
startnumberStart time in Unix Timestamp - Optional. Default 7 days ago
endnumberEnd time in Unix timestamp - Optional. Default - now
attrsarrayWhat attributes we are quering for. Optional. Default 'bytes', 'wan-tx_bytes', 'wan-rx_bytes', 'wlan_bytes', 'num_sta', 'lan-num_sta', 'wlan-num_sta', 'time'
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_hourly_ap(start, end, attrs, site) ⇒ Promise

List hourly site statistics for ap

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
startnumberStart time in Unix Timestamp - Optional. Default 7 days ago
endnumberEnd time in Unix timestamp - Optional. Default - now
attrsarrayWhat attributes we are quering for. Optional. Default 'bytes', 'num_sta', 'time'
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_sta_sessions_latest(mac, limit, sort, site) ⇒ Promise

Last station sessions

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
limitnumberHow many sessions. Optional. Default 5
sortstringSorting. Optional. Default Ascending (asc)
sitestringUbiquiti site, if different from default - optional

Example

unifi.stat_sta_sessions_latest('00:01:02:03:04:05', 10)
    .then(done => console.log('Success', done))
    .catch(err => console.log('Error',err))

unifiAPI.stat_auths(start, end, site) ⇒ Promise

List authorizations

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
startnumberStart time in Unix Timestamp - Optional. Default 7 days ago
endnumberEnd time in Unix timestamp - Optional. Default - now
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_allusers(historyhours, site) ⇒ Promise

List all users

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
historyhoursnumberHow many hours back to query. Optional. Default 8670
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_guests(historyhours, site) ⇒ Promise

List of guests (authorized via the guest portal)

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
historyhoursnumberHow many hours back to query. Optional. Default 8670
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_guests2(historyhours, site) ⇒ Promise

List of guests (authorized via the guest portal) but with modern internal api

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
historyhoursnumberHow many hours back to query. Optional. Default 8670
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_clients(mac, site) ⇒ Promise

List of (all) clients per station

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_some_clients(macs, ap, site) ⇒ Promise

List of group of clients per station

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macsstringString mac or array of mac addresses as strings, to get information about them
apstringStation man address
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.stat_client(mac, site) ⇒ Promise

Statistics of (all) clients per station

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringMac address
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_usergroup(site) ⇒ Promise

List of the usergroups

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.set_usergroup(userid, groupid, site) ⇒ Promise

Add user to a group

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
useridstringID of the user
groupidstringID of the group
sitestringUbiquiti site, if different from default - optional

Example

unifi.set_usergroup('11aa22bb33cc44dd55ee66ff', '112233445566778899aabb')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.list_health(site) ⇒ Promise

List health

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_dashboard(site) ⇒ Promise

List dashboard

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_users(site) ⇒ Promise

List users

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_aps(mac, site) ⇒ Promise

List APs

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringAP mac/id, Optional
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_rogueaps(within, site) ⇒ Promise

List Rogue APs

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
withinnumberFor how many hours back. Optional. Default 24h
sitestringUbiquiti site, if different from default - optional

Example

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

unifiAPI.list_sites() ⇒ Promise

List sites

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

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

unifiAPI.stat_sites() ⇒ Promise

Sites stats

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

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

unifiAPI.add_site(name, description, site) ⇒ Promise

Add new site

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
namestringname
descriptionstringdescription - optional
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.add_site('mysite','Experimental site')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.remove_site(name, site) ⇒ Promise

Remove site

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
namestringname
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_wlan_groups(site) ⇒ Promise

List WLANGroups

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.stat_sysinfo(site) ⇒ Promise

Stat Sysinfo

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_self(site) ⇒ Promise

Get information aboult self (username, etc)

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_networkconf(site) ⇒ Promise

Get information aboult the network configuration

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.stat_voucher(createtime, site) ⇒ Promise

Get accounting / status of the vouchers

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
createtimenumberUnixtimestamp since when we return information about the vouchers. Optional. Default any
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.stat_payment(within, site) ⇒ Promise

Get accounting / status of the payments

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
withinnumberhow many hours back we query. Optional. Default any
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.create_hotspot(name, password, note, site) ⇒ Promise

Create HotSpot (version 1)

Kind: instance method of UnifiAPI
Returns: Promise - Promise
Todo

  • Check if the URL of the rest service is correct
  • Test that it is working
ParamTypeDescription
namestringname
passwordstringpassword
notestringNote (optional)
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.create_hotspot('myhotspot', 'password', 'note')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.list_hotspot(site) ⇒ Promise

List all of the hotspots (v1)

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.create_voucher(count, minutes, quota, note, up, down, mbytes, site) ⇒ Promise

Create vouchers. Generate a set of vouchers

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
countnumberhow many vouchers to generate. Optional. default is 1
minutesnumberhow long the voucher may be active after activation in minutes. Optional. default is 60 minutes
quotanumberhow many times a user may reuse (login with) this voucher. Default 0 = unlimited. 1 means only once. 2 means two times and so on
notestringthe note of the voucher. Optional
upnumberUpstream bandwidth rate limit in Kbits. Optional. Default - no limit
downnumberDownstream bandwidth rate limit in Kbits. Optional. Default - no limit
mbytesnumberLimit of the maximum download traffic in Mbytes. Optional. Default - no limit
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.create_voucher(10, 2880, 1, 'Test vouchers', 1000, 2000, 250)
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.revoke_voucher(voucher_id, site) ⇒ Promise

Revoke Voucher. Voucher revoking is the same as deleting the voucher. In most of the cases the authorized user is kicked out of the network too

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
voucher_idstringdescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_portforwarding(site) ⇒ Promise

List port forwarding configuration

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_dynamicdns(site) ⇒ Promise

List dynamic dns configuration

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_portconf(site) ⇒ Promise

List network port configuration

Kind: instance method of UnifiAPI
Returns: Promise - Promise
Todo

  • Test it
ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_extension(site) ⇒ Promise

List extensions

Kind: instance method of UnifiAPI
Returns: Promise - Promise
Todo

  • Learn more what exactly is this
ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.list_settings(site) ⇒ Promise

Get array with all the settings refered by settings key

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.restart_ap(mac, site) ⇒ Promise

Restart Wireless Access Point

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringmac address of the AP
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.restart_ap('00:01:02:03:aa:04')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.disable_ap(ap_id, disable, site) ⇒ Promise

Disable Wireless Access Point

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringThe internal ID of the AP
disablebooleanShall we disable it. Optional. Default true. If false, the AP is enabled
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.enable_ap(ap_id, disable, site) ⇒ Promise

Enable Wireless Access Point

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringThe internal ID of the AP
disablebooleanShall we disable it. Optional. Default true. If false, the AP is enabled
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.set_locate_ap(mac, site) ⇒ Promise

Locate Wireless Access Point. The Access Point will start blinking

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringmac of the AP
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.set_locate_ap('00:01:aa:03:04:05')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.unset_locate_ap(mac, site) ⇒ Promise

Turn off Locate Wireless Access Point. The Access Point will stop blinking

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
macstringmac of the AP
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.unset_locate_ap('00:01:aa:03:04:05')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.site_ledson(site) ⇒ Promise

All devices in the site group will start blinking

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.site_ledsoff(site) ⇒ Promise

All devices in the site group will stop blinking

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.set_ap_radiosettings(ap_id, radio, channel, ht, tx_power_mode, tx_power, site) ⇒ Promise

Change AP wireless settings

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringinternal id of the AP
radiostringThe radio type. Supports ng or ac. Default ng. Optional
channelnumberWireless channel. Optional. Default 1. Could be string 'auto'
htnumberHT width in MHz. 20, 40, 80, 160. Optional. Default 20
tx_power_modenumberTX Power Mode. Optional. Default 0
tx_powernumberTX Power. Optional. Default 0
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.set_ap_radiosettings('aa0101023faabbaacc0c0', 'ng', 3, 20)
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.get_settings_by_key(key, site) ⇒ Promise

Retrieve settings by a specific settings key. Only elements with this settings key will be returned in the array. Usually 1 or 0 Typical keys are mgmt, snmp, porta, locale, rsyslogd, auto_speedtest, country, connectivity

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
keystringkey
sitestringUbiquiti site to query, if different from default - optional

Example

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

unifiAPI.set_settings(key, obj, site) ⇒ Promise

Set settings by key modifies properties of the settings, defined by key

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
keystringkey
objobjectobject of properties that overwrite the original values
sitestringUbiquiti site to query, if different from default - optional

Example

unifi.set_settings_by_key('mgmt', { auto_upgrade: true })
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.set_guest_access(obj, guest_id, site_id, site) ⇒ Promise

Set Guest Settings and Guest Access Portal are created with this method

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
objobjectObject of properties that modify the original values
obj.authstringOptional. Type of authentication. hotspot, radius, none, .... Default hotspot
obj.expirestringOptional. How long the authentication is valid in minutes. Default 480 (8h)
obj.facebook_enabledbooleanOptional. Allow authentication with facebook. Default false
obj.google_enabledbooleanOptional. Allow authentication with google+. Default false
obj.paymentbooleanOptional. Allow payments for authentication. Default false
obj.portal_customizedbooleanOptional. Customize the auth portal. Default false
obj.portal_enabledbooleanOptional. Enable the portal. Default true
obj.redirect_enabledbooleanOptional. Redirect after authentication. Default false
obj.redirect_urlstringOptional. Redirect URL after successful authentication. Default empty
obj.voucher_enabledbooleanOptional. If voucher authentication is enabled. Default false
guest_idstringFrom the get_settings, the ID of the guest settings
site_idstringThe ID of the current site
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_guest_access({ auth: 'hotspot', payment_enabled: true }, 'aabbaa01010203','ccffee0102030303')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.set_guestlogin_settings(portal_enabled, portal_customized, redirect_enabled, redirect_url, x_password, site) ⇒ Promise

Set Guest Login Settings (simplified version)

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
portal_enabledbooleanIf the portal is enabled. Optional. Default true
portal_customizedbooleanIf the portal is customized. Optional. Default true
redirect_enabledbooleanIf the redirection is enabled. Optional. Default false
redirect_urlstringThe url for redirection. Optional. Default ''
x_passwordstringPassword for the portal. Optional. Default ''
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_guestlogin_settings(true, true, true, 'http://news.com')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.rename_ap(ap_id, ap_name, site) ⇒ Promise

Rename Access Point

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringId of the AP
ap_namestringNew name of the AP
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.rename_ap('ccffee0102030303','My Access Point')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.set_wlansettings(wlan_id, x_password, name, site) ⇒ Promise

Set WLAN Settings

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
wlan_idstringsID of the Wlan
x_passwordstringPassword of the WLAN
namestringName of the WLAN
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_wlansettings('ccffee0102030303', 'guest', 'GuestWLAN')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.list_events(site) ⇒ Promise

List the Events

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.list_wlanconf(site) ⇒ Promise

Get WLAN Config. Respond with Array of Wlan configurations

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.get_wlanconf(site) ⇒ Promise

Get WLAN Config. Second REST option. Respond with Array of Wlan configurations

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.list_alarms(site) ⇒ Promise

List the Alarms

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.set_ap_led(ap_id, led_override, site) ⇒ Promise

Set the access point LED

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringAP ID
led_overridestringDo we follow the standard LED config. Options default and overwrite
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.set_ap_name(ap_id, name, site) ⇒ Promise

Change the name of an Access Point

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringthe ID of the AP
namestringthe new name
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_ap_name('12312312312','new ap')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.set_ap_wireless(ap_id, radio, channel, ht, min_rssi, min_rssi_enabled, antenna_gain, tx_power_mode, site) ⇒ Promise

Set wireless properties per AP

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringthe ID of the AP
radiostringradio type. ng/ac/bg. Optional. Default ng
channelnumberThe channel number or auto. Optional. Default auto.
htnumberchannel width. 20/40/80/160. Optional. Default 20.
min_rssinumberMinimal RSSI accepted in dbi. Optional. Default -94
min_rssi_enabledbooleanIf enabled, drops users bellow that rssi valur. Optional. Default false
antenna_gainnumberThe antenna gain. Optional. Default 6 dbi
tx_power_modestringTX Power Mode. Optional. Default auto
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_ap_wireless('12312312312','ng', 3)
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.status(site) ⇒ Promise

Check status

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
sitestringUbiquiti site to query, if different from default - optonal

Example

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

unifiAPI.set_ap_network(ap_id, type, ip, netmask, gateway, dns1, dns2, site) ⇒ Promise

Configure the network settings of AP/device

Kind: instance method of UnifiAPI
Returns: Promise - Promise

ParamTypeDescription
ap_idstringID of the AP
typestringstatic or dhcp. Optional. Default dhcp
ipstringIP address. Optional
netmaskstringnetmask. Optional
gatewaystringgateway. Optional
dns1stringdns. Optional
dns2stringdns. Optional
sitestringUbiquiti site to query, if different from default - optonal

Example

unifi.set_ap_network('00:01:02:03:04:05', 'dhcp')
    .then(done => console.log('Success',done))
    .catch(err => console.log('Error',err))

unifiAPI.request_spectrumscan

0.0.54

4 years ago

0.0.53

6 years ago

0.0.52

6 years ago

0.0.51

6 years ago

0.0.50

6 years ago

0.0.49

7 years ago

0.0.48

7 years ago

0.0.47

7 years ago

0.0.46

7 years ago

0.0.45

7 years ago

0.0.44

7 years ago

0.0.43

7 years ago

0.0.42

7 years ago

0.0.41

7 years ago

0.0.40

7 years ago

0.0.39

7 years ago

0.0.38

7 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago