Install & initialize
The Node SDK (@optomatica/optolink-sdk) is a zero-dependency TypeScript client for the OptoLink /links API — create, read, list, update, delete links and fetch QR codes. It runs on Node 18+ (native fetch), ships dual ESM + CJS builds with full TypeScript types, and is compatible with OptoLink backend v2.1.0+.
Requirements
- Node ≥ 18
- A SERVER-tier API key (
opl_api_…), minted on the OptoLink portal's API keys page (the Server API Key card). CLIENT-tier keys (opl_sdk_…) are rejected with403on the links API. - An OptoLink backend at v2.1.0 or newer.
Install
npm add @optomatica/optolink-sdk
# or
pnpm add @optomatica/optolink-sdk
# or
yarn add @optomatica/optolink-sdk
The package has zero runtime dependencies — everything rides on Node's built-in fetch.
Initialize
Both import styles work (default and named):
import OptoLink from "@optomatica/optolink-sdk";
// equivalently: import { OptoLink } from "@optomatica/optolink-sdk";
const client = new OptoLink({ apiKey: "opl_api_…" });
The constructor is the only place configuration happens — there are no per-request overrides.
| Option | Default | Notes |
|---|---|---|
apiKey | — (required) | SERVER-tier key, sent as Authorization: Bearer … on every request. Missing or empty throws a TypeError at construction — there is no env-var fallback. |
baseUrl | https://api.optolink.app | The OptoLink API origin. Trailing slashes are stripped on assignment. Pass your own deployment's origin to target it. |
timeout | 10_000 | Milliseconds per HTTP attempt, enforced with an AbortController. |
retries | 2 | Retry budget, shared across all attempts of one call (see errors & retries). |
Verify it works
Any call proves the key and network are good — listing links is the read-only smoke test:
const page = await client.links.list({ page: 1, limit: 1 });
console.log(page.total);
Next: create your first link.