Skip to main content
Install the official soundlink package to call the Public API with full TypeScript types. For raw HTTP, see Quickstart. Not sure which approach fits your stack? See SDK overview.

Prerequisites

  • API key (sk_*) with the scopes you need — Authentication
  • Node.js 18+ or an Edge runtime with fetch
Store the key in an environment variable (e.g. SOUNDLINK_API_KEY). Never hardcode keys or ship them to the browser.

1. Install

2. Initialize the client

You can also pass the key as a string: new Soundlink('sk_your_prefix_your_secret'). The client sends x-api-key on every request. Your organization is determined from the key.

3. Ping and list campaigns

List and get require the campaigns:read scope. Equivalent curl examples are in Quickstart.

Paginate all campaigns

Create and manage wallet campaigns

Requires campaigns:write. Write methods take { idempotencyKey } — the SDK sends the Idempotency-Key header. Only generation: 3 (wallet) campaigns support budget, tiers, and stop. See Creating campaigns and Managing campaigns.

Response pattern

Every method returns { data, error, meta? } — the same envelope as the REST API. HTTP errors are not thrown; check error and use requestId when contacting support.
Do not use try/catch for normal API failures. The SDK only throws for configuration, parse, or transport errors. See Errors below and Errors for API codes.

Metrics and exports

For smaller datasets: await soundlink.metrics.breakdown.export.collect('f1e28d31-c358-4284-9bef-00a2334625fd'). Engagement exports work the same way: soundlink.metrics.engagement.export and .export.collect. See Understanding metrics and JSONL exports.

Configuration

Methods

Every method maps 1:1 to a Public API route. All return Promise<ApiResponse<T>> unless noted.

System

Strategies

Requires campaigns:read.

Campaigns (read)

Requires campaigns:read. list params: page, pageSize (max 100), sortBy (createdAt | status), sortOrder (asc | desc).

Campaigns (write)

Requires campaigns:write. Pass { idempotencyKey } on create, stop, and budget methods. Wallet campaigns only (generation: 3) for budget / tiers / stop.

Metrics

Requires metrics:read. Date params use inclusive YYYY-MM-DD. Export windows are capped at 90 days per request. Breakdown list pageSize max is 500.

Types

All public types are exported from soundlink for use in your app:
Row shapes match the warehouse schemas documented in Understanding metrics. For full field lists, use the API Reference or your IDE hover hints on the imported types.

Errors

The SDK has two error paths. Most of the time you only need the first.

API errors (returned, not thrown)

When the Public API returns 4xx or 5xx, the SDK resolves with { data: null, error, meta? }:
Always check error before using data. Error codes and HTTP mapping: Errors.

SDK errors (thrown)

These extend SoundlinkSdkError and mean something went wrong outside a normal API response:
Use try/catch for client setup and rare transport failures. Use { data, error } for everything the API returns.

Next

Creating campaignsManaging campaignsSyncing campaignsUnderstanding metrics