npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@serkonda7/unifi-api

v0.1.1

Published

TypeScript client for the UniFi Site Manager API

Readme

unifi-api

CI npm version npm updated

TypeScript client for the UniFi Site Manager API.

ℹ️ Disclaimer

This project is an unofficial API client for the UniFi Site Manager API.

It is not affiliated with, endorsed by, or sponsored by Ubiquiti Inc. UniFi and related trademarks are the property of Ubiquiti Inc.

Use of this package requires a UniFi account and a Site Manager API key.

The authors provide this client as-is and make no guarantees regarding correctness, availability, compatibility, or future changes of the UniFi Site Manager API.

📦 Installation

bun install @serkonda7/unifi-api

🚀 Usage

Also check out the official UniFi Site Manager API docs: https://developer.ui.com/site-manager-api/

To get an API key, sign in at https://unifi.ui.com, open the API section, and create an API key. Personal API keys can only reach consoles owned by your account; organization API keys can reach all consoles in the organization.

Site Manager endpoints are rate limited — a client that exceeds its limit receives HTTP 429 with a Retry-After header.

Create the client

import { createUnifiClient } from '@serkonda7/unifi-api'

const unifi = createUnifiClient({
  apiKey: process.env.UNIFI_API_KEY!,
  // baseUrl defaults to https://api.ui.com
})

Each client owns an isolated instance, so auth can't leak between clients. Rotate the key later with unifi.setApiKey(nextKey). unifi.instance exposes the underlying hey-api client (interceptors, raw SDK calls).

Make requests

import { createUnifiClient, UnifiApiError } from '@serkonda7/unifi-api'

const unifi = createUnifiClient({ apiKey: process.env.UNIFI_API_KEY! })

try {
  // GET /v1/hosts — follows `nextToken` pagination automatically
  const hosts = await unifi.hosts.listAll()

  // GET /v1/hosts/{id}
  const hostId = hosts[0]?.id
  if (hostId) {
    const host = await unifi.hosts.get(hostId)

    // GET /v1/devices, filtered by host
    const devices = await unifi.devices.listAll({ hostIds: [hostId] })
  }

  // GET /v1/sites
  for await (const site of unifi.sites.iterate()) {
    console.log(site.siteId, site.hostId, site.isOwner)
  }

  // GET /v1/isp-metrics/{type}
  const metrics = await unifi.ispMetrics.get('5m', { duration: '24h' })
} catch (error) {
  if (error instanceof UnifiApiError) {
    console.error(error.status, error.code, error.message, error.traceId, error.retryAfter)
  } else {
    throw error
  }
}

Methods return the response's data directly. List methods return { data, nextToken } pages, iterate() is an async generator that follows pagination, and listAll() collects all pages. Non-2xx responses throw a UnifiApiError with the fields status, code, message, traceId, retryAfter, and body.

Available resources:

| Resource | Methods | Endpoint(s) | | --- | --- | --- | | hosts | list, iterate, listAll, get | GET /v1/hosts, GET /v1/hosts/{id} | | sites | list, iterate, listAll | GET /v1/sites | | devices | list, iterate, listAll | GET /v1/devices | | ispMetrics | get, query | GET /v1/isp-metrics/{type}, POST /v1/isp-metrics/{type}/query | | sdWan | list, get, status | GET /v1/sd-wan-configs, GET /v1/sd-wan-configs/{id}, GET /v1/sd-wan-configs/{id}/status | | connector | get, post, put, patch, delete, request, forConsole, network, protect | * /v1/connector/consoles/{id}/{path} |

Full method reference (regenerated via bun run docs): docs/unifi-client.html.

🔌 Cloud connector

The connector proxies requests through api.ui.com to the local UniFi applications (Network, Protect, InnerSpace) running on a console. It requires console firmware ≥ 5.0.3 and is limited to 100 requests/minute per console, a 25 s timeout, and a 10 MB response body. The upstream response is passed through unchanged (it is not wrapped).

const hostId = '900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789'

// GET /v1/connector/consoles/{hostId}/network/integration/v1/sites
const network = unifi.connector.network(hostId)
const sites = await network.get<{ data: { id: string; name: string }[] }>('/v1/sites')

// GET /v1/connector/consoles/{hostId}/protect/integration/v1/meta/info
const info = await unifi.connector.protect(hostId).get('/v1/meta/info')

// Any other path, any method
await unifi.connector.post(hostId, `network/integration/v1/sites/${siteId}/...`, { /* body */ })

See the Network API docs at https://developer.ui.com/network and the Protect API docs at https://developer.ui.com/protect.

🧰 Generated SDK

The raw hey-api functions (listHosts, getHostById, listSites, listDevices, getIspMetrics, queryIspMetrics, listSdWanConfigs, getSdWanConfigById, getSdWanConfigStatus) are exported too. They return { data, error } unions. Configure the shared singleton:

import { client, listHosts } from '@serkonda7/unifi-api'

client.setConfig({ auth: process.env.UNIFI_API_KEY! })

const { data, error } = await listHosts({ query: { pageSize: '50' } })

Note: the generated connector* functions cannot be used for real requests (the spec's wildcard path is not expanded) — use unifi.connector instead.

🛠️ Development

  • bun install — install dependencies
  • bun run generate — regenerate src/generated from openapi/site-manager-1.0.0.json
  • bun run check — type-check the project
  • bun run lint — lint/format with Biome
  • bun test — run the test suite
  • bun run build — build the package
  • bun run docs — generate the method reference

📜 License

The UniFi Site Manager API and its specification are provided by Ubiquiti Inc. under their terms.