UniLink JavaScript SDK (Build With UniLink Using Node.js or the Browser)

By UniLink May 02, 2026 10 min read
UniLink JavaScript SDK (Build With UniLink Using Node.js or the Browser)


UniLink JavaScript SDK (Build With UniLink Using Node.js or the Browser)

The official UniLink JavaScript SDK wraps the REST API in a typed, promise-based client that works in Node.js and modern browsers — install in one command and start building immediately.

  • Install with npm install @unilink/sdk, initialize with your API key, and call methods like contacts.create() and orders.list().
  • Full TypeScript types are included — autocomplete and compile-time checks work out of the box.
  • Works in Node.js for server-side scripts and in the browser for client-side tools, with the same API surface.

Raw REST API calls are straightforward for one-off scripts, but as an integration grows — more endpoints, more error handling, more type safety — the overhead of manually building headers, encoding parameters, and parsing responses adds up. The UniLink JavaScript SDK handles all of that plumbing. You initialize it once with your API key, and every subsequent call is a clean method invocation with typed parameters and a typed return value. Whether you are building a Node.js automation script, a Next.js dashboard, or a browser-based tool, the same SDK package works across all environments without any modification.

What the JavaScript SDK Does

The SDK is a thin, opinionated wrapper over the UniLink REST API. It handles authentication — the Bearer token is set once at initialization and attached to every request automatically. It handles pagination — methods that return lists expose an async iterator pattern that yields results page by page without you managing cursor or page parameters manually. It handles errors — HTTP error responses are converted to typed error objects with a status code and a message field, so you can catch and branch on specific API errors rather than parsing raw response bodies. And it handles serialization — request bodies and response objects are automatically JSON-serialized and deserialized.

The SDK is organized into resource modules that mirror the API structure: pages, contacts, orders, products, analytics, and domains. Each module exposes methods that map directly to API endpoints: list(), get(id), create(data), update(id, data), and delete(id) where applicable. Method names follow the same pattern across all resources, so once you learn the pattern for one resource, all others work the same way. TypeScript users get full type inference on both the input parameters and the return values — pass a wrong field name and TypeScript flags it before the code runs.

The SDK works in both CommonJS and ES module environments. For Node.js 18+, import it as an ES module: import { UniLink } from '@unilink/sdk'. For older Node.js or CommonJS environments: const { UniLink } = require('@unilink/sdk'). For browser use, the SDK uses the native fetch API available in all modern browsers — no polyfills required for Chrome 90+, Firefox 90+, Safari 15+, or Edge 90+. Bundle it with your build tool of choice (Webpack, Vite, Rollup) and tree-shaking removes any resource modules you do not use.

How to Get Started

  1. Install the package: npm install @unilink/sdk (or yarn add @unilink/sdk / pnpm add @unilink/sdk). The package includes TypeScript type definitions — no @types/ package needed.
  2. Generate an API key from Settings → API at app.unilink.us. Choose the scope your integration requires: read for read-only operations, write for create/update, admin for delete.
  3. Initialize the client: import { UniLink } from '@unilink/sdk'; const client = new UniLink({ apiKey: process.env.UNILINK_API_KEY });. Store the key in an environment variable — never hardcode it.
  4. Make your first call: const pages = await client.pages.list(); console.log(pages.data);. Confirm you receive an array of page objects matching your account.
  5. Test a write operation if your key has write scope: const contact = await client.contacts.create({ email: 'test@example.com', tags: ['sdk-test'] });. Confirm the contact appears in your dashboard.

How to Use the JavaScript SDK

  1. List resources: const result = await client.orders.list({ status: 'pending', per_page: 50 }); — the result.data array contains the items, result.total has the full count, and result.has_more indicates whether to fetch the next page.
  2. Get a single resource: const order = await client.orders.get('order_abc123'); — pass the resource ID as a string. The return type is a single typed object, not an array.
  3. Create a resource: const product = await client.products.create({ name: 'My Course', price: 4900, type: 'digital' }); — the response is the created object including the server-assigned id.
  4. Update a resource: await client.products.update('prod_xyz', { price: 3900 }); — pass only the fields to change; the SDK sends a partial update (PUT) with just those fields.
  5. Fetch analytics: const stats = await client.analytics.summary({ start_date: '2026-04-01', end_date: '2026-04-30', granularity: 'week' }); — the return type includes a typed series array for time series data.

Key Settings

SettingWhat It DoesRecommended
apiKeyYour UniLink Bearer token, passed to the constructor and attached to every request automaticallyLoad from environment variable — process.env.UNILINK_API_KEY in Node.js, an injected build-time variable in browser builds
baseUrlThe API base URL — defaults to https://unilink.us/api/v1Leave as default for production; override to a local proxy URL during testing if needed
timeoutRequest timeout in milliseconds — defaults to 30000 (30 seconds)Lower to 10000 for user-facing operations where a slow response should fail fast; keep default for batch jobs
retriesNumber of automatic retries on network errors and 429/503 responses — defaults to 2Keep at 2 for production reliability; set to 0 during testing to see errors immediately
Per-method filtersTyped filter objects passed to list() methods — e.g., { status: 'pending', start_date: '...' }Always pass filters rather than fetching all records and filtering client-side — filters run server-side and reduce response size
Tip: For Node.js scripts that process large datasets, use the SDK's async iterator instead of manual pagination: for await (const contact of client.contacts.iterate()) { process(contact); }. The iterator automatically fetches the next page as you consume results, giving you a clean loop over your entire contact list without managing page numbers or cursor tokens yourself.

Get the Most Out Of the JavaScript SDK

Structure your integration as a set of small, focused async functions — one function per operation — rather than a single monolithic script. Each function accepts typed parameters, calls one SDK method, and returns a typed result. This pattern makes your integration testable: you can mock the SDK client in tests and verify each function's behavior independently without making real API calls. The SDK's TypeScript types make the mock setup straightforward because the type signatures tell you exactly what shape the mock must return.

For Next.js applications, initialize the SDK client in a shared module and import it in your API routes or server actions. Do not initialize a new client per request — the client is stateless after initialization (the API key is set once and reused) and creating a new instance on every request wastes memory. A module-level singleton is the correct pattern for long-running Node.js processes and serverless functions where module caching applies.

When building browser-based tools that call the UniLink API directly — for example, a Chrome extension or a client-side dashboard widget — be careful about where the API key is loaded from. Browser-accessible environment variables are visible to any user who inspects the page source or network traffic. For browser use cases with sensitive data, route API calls through your own backend endpoint that holds the API key server-side, rather than exposing the key in the browser bundle.

Handle SDK errors with typed catches. The SDK throws instances of UniLinkError for API errors, which has a status property (HTTP status code) and a message string. Wrap SDK calls in try/catch blocks and check error.status === 429 to detect rate limiting, error.status === 404 to detect missing resources, and error.status === 409 to detect conflicts like duplicate contacts. Branching on these specific codes makes your integration resilient without catching and swallowing unrelated errors.

Troubleshooting

ProblemCauseFix
UniLinkError: 401 UnauthorizedAPI key is missing, undefined, or not attached to the constructorConfirm process.env.UNILINK_API_KEY is set and non-empty before initializing the client; log the key prefix (first 8 chars) to verify it loaded
TypeScript type errors on method parametersPassing wrong field types or misspelled field namesCheck the SDK's type definitions with your IDE's hover tool — the exact accepted fields and types are annotated in the package; do not cast to any to bypass type errors
SDK not found in browser bundleBuild tool not resolving the package or a peer dependency missingConfirm the package is in dependencies (not devDependencies) in package.json; run npm install to ensure it is installed
Method returns empty data despite records existingFilter parameters are too restrictive or the wrong scope key is usedCall the method without filters first to confirm records are returned; check the API key scope matches the operation
  • Full TypeScript types eliminate a class of API integration bugs at compile time, before code runs
  • Automatic auth, retries, and pagination handle the boilerplate that raw fetch calls require you to write manually
  • Works in Node.js and browser environments without any configuration changes
  • Consistent resource module pattern means learning one resource teaches you the pattern for all others
  • Adds a dependency to your project — direct fetch calls are lighter for very simple, single-endpoint integrations
  • Browser use requires careful API key handling — keys should never appear in client-side bundles for production apps
  • SDK version must be kept updated to access new API endpoints as they are added
Does the SDK work with Deno or Bun?

Yes — the SDK uses standard ES module syntax and the native fetch API, both of which are supported by Deno and Bun. For Deno, import from npm using npm:@unilink/sdk. For Bun, install and use it exactly as you would with Node.js.

Can I use the SDK without TypeScript?

Yes — the SDK works in plain JavaScript. TypeScript type definitions are included but entirely optional. In a JavaScript project, you get the same runtime behaviour without any type annotations — the IDE may still show type hints via JSDoc inference, but no TypeScript compilation is required.

How do I handle pagination for large datasets?

Use the async iterator: for await (const item of client.contacts.iterate(filters)) { ... }. Alternatively, call list() manually and check result.has_more to decide whether to fetch the next page with an incremented page parameter.

Does the SDK support webhook signature verification?

Yes — the SDK includes a webhooks.verify(payload, signature, secret) utility that validates UniLink webhook request signatures. Use it in your webhook endpoint handler to confirm requests are genuinely from UniLink before processing them.

What version of the UniLink API does the SDK use?

The SDK targets https://unilink.us/api/v1 by default. As the API evolves, the SDK is versioned to match. Check the package changelog at npmjs.com for version-specific changes and any breaking changes when upgrading the package.

  • Install with npm install @unilink/sdk, initialize with new UniLink({ apiKey: process.env.UNILINK_API_KEY }), and call methods like client.contacts.create().
  • TypeScript types are included — IDE autocomplete and compile-time checks work without any additional setup.
  • Resources follow a consistent pattern: list(), get(id), create(data), update(id, data), delete(id).
  • Use the async iterator (client.resource.iterate()) for large datasets — it handles pagination automatically.
  • Never expose API keys in browser bundles — route browser-side calls through your own backend endpoint for production apps.

Start building with the UniLink JavaScript SDK — run npm install @unilink/sdk, grab your API key from app.unilink.us under Settings → API, and make your first typed API call in minutes.

Create Your Free Link-in-Bio Page

Join thousands of creators using UniLink. 40+ blocks, analytics, e-commerce, and AI tools — all free.

Get Started Free