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. To run the campaign lifecycle on your machine, see API emulator.

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 Authorization: Bearer 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.
List, get, and metrics require soundlinks:read. Create and delete require soundlinks:write. Returns only soundlinks not linked to a campaign — campaign-backed links use the Campaigns API. Responses have no spend or fee fields (ads run in your Meta account).
Full REST guides: Syncing soundlinks · Soundlink metrics · Creating soundlinks. Scopes: Authentication.

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.

Campaign 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 Campaign 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). activity is a page of creative adds, budget changes, and other campaign events. startDate is YYYY-MM-DD (from 00:00:00Z) or an ISO-8601 timestamp. Omit it for the full history. page defaults to 1. pageSize defaults to 20 and maxes at 100. See Activity. For multi-campaign reads, use the REST batch routes in Campaign metrics and Activity.

Campaigns (write)

Requires campaigns:write. Pass { idempotencyKey } on create, stop, and budget methods. Wallet campaigns only (generation: 3) for budget / tiers / stop. Requires soundlinks:read. Self-serve soundlinks only (not campaign-linked). Breakdown and engagement helpers require soundlink 2.2.0+. list params: page, pageSize (max 100), sortBy (createdAt), sortOrder (asc | desc). Breakdown and engagement list pageSize max is 500. Export windows are capped at 90 days per request. create requires soundlinks:write and { idempotencyKey }. Optional appleMusicUrl and youtubeMusicUrl are HTTPS song or playlist URLs. Songs and catalog playlists are checked with the provider; missing content returns 400 invalid_request. An Apple library playlist is format-checked only, and an Apple album share-sheet link (?i=) is stored as the canonical song URL. Optional attributionEnabled defaults to true; false skips Spotify login and cannot be combined with autoFollow: true. Optional streamValueEventEnabled defaults to false. true turns on Soundlink Stream Value when your organization is already enabled for it, and cannot be combined with attributionEnabled: false. Otherwise create returns 403 stream_value_not_enabled. Detail returns the music URLs, attributionEnabled, and streamValueEventEnabled. List items do not include them. delete archives the soundlink and does not send Idempotency-Key. URL rules: Creating soundlinks.

Campaign 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. Paginated campaign engagement (GET .../metrics/engagement) is not in the SDK — use the HTTP path in Campaign metrics. creatives is a lifetime snapshot grouped by background video. Each child has the audio cut as timestamp_start_ms and timestamp_end_ms (both null when the cut is not a ready sound). It rejects dates. creativeDaily is one row per day and Meta ad creative: spend_media, impressions, followers, and cpf. cpf is null when followers is zero. pageSize defaults to 50 and maxes at 500. Omit both dates for every day that has rows. See Creative daily.

Types

All public types are exported from soundlink for use in your app:
Row shapes match the warehouse schemas documented in Campaign 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

Syncing soundlinks → Creating soundlinks → Creating campaigns → Managing campaigns → Campaign metrics